perf: add benchmark defaults to external pools benchmark
[poolifier.git] / benchmarks / versus-external-pools / dynamic-worker-nodes.js
CommitLineData
589f0f1c 1'use strict'
bea2d6e3 2const WorkerNodes = require('worker-nodes')
91a40166 3const { BenchmarkDefaults } = require('./utils.mjs')
479ba9f6 4
91a40166
JB
5const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
6const numIterations =
7 parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
6c063733
JB
8const data = {
9 test: 'MYBENCH',
91a40166
JB
10 taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
11 taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
6c063733
JB
12}
13
14const workerNodes = new WorkerNodes(
bea2d6e3 15 require.resolve('./workers/worker-nodes/function-to-bench-worker'),
6c063733 16 {
02749105
JB
17 minWorkers: Math.floor(size / 2),
18 maxWorkers: size,
6c063733
JB
19 taskTimeout: 60000 // this is the same as poolifier default
20 }
21)
22
23async function run () {
1655b92e 24 const promises = new Set()
91a40166 25 for (let i = 0; i < numIterations; i++) {
1655b92e 26 promises.add(workerNodes.call.functionToBench(data))
6c063733
JB
27 }
28 await Promise.all(promises)
2f8c5b5c 29 // eslint-disable-next-line n/no-process-exit
6c063733
JB
30 process.exit()
31}
32
bea2d6e3
JB
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})()