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