9400840088e33e201d4526929606a9d3133a814d
[poolifier.git] / benchmarks / versus-external-pools / fixed-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: size,
17 maxWorkers: size,
18 taskTimeout: 60000 // this is the same as poolifier default
19 }
20 )
21
22 async function run () {
23 const promises = new Set()
24 for (let i = 0; i < iterations; i++) {
25 promises.add(workerNodes.call.functionToBench(data))
26 }
27 await Promise.all(promises)
28 // eslint-disable-next-line n/no-process-exit
29 process.exit()
30 }
31 ;(async () => {
32 try {
33 await run()
34 } catch (e) {
35 console.error(e)
36 // eslint-disable-next-line n/no-process-exit
37 process.exit(1)
38 }
39 })()