9af2936b7c0af5f15a6d5830905b62f7e690a70d
[poolifier.git] / benchmarks / versus-external-pools / fixed-worker-nodes.js
1 'use strict'
2 const WorkerNodes = require('worker-nodes')
3 const { BenchmarkDefaults } = require('./utils.mjs')
4
5 const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
6 const numIterations =
7 parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
8 const data = {
9 test: 'MYBENCH',
10 taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
11 taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
12 }
13
14 const workerNodes = new WorkerNodes(
15 require.resolve('./workers/worker-nodes/function-to-bench-worker'),
16 {
17 minWorkers: size,
18 maxWorkers: size,
19 taskTimeout: 60000 // this is the same as poolifier default
20 }
21 )
22
23 async function run () {
24 const promises = new Set()
25 for (let i = 0; i < numIterations; i++) {
26 promises.add(workerNodes.call.functionToBench(data))
27 }
28 await Promise.all(promises)
29 // eslint-disable-next-line n/no-process-exit
30 process.exit()
31 }
32
33 (async () => {
34 try {
35 await run()
36 } catch (e) {
37 console.error(e)
38 // eslint-disable-next-line n/no-process-exit
39 process.exit(1)
40 }
41 })()