Merge branch 'master' into feature/task-functions
[poolifier.git] / benchmarks / versus-external-pools / dynamic-node-worker-threads-pool.mjs
... / ...
CommitLineData
1import { DynamicPool } from 'node-worker-threads-pool'
2import { executeAsyncFn } from '../benchmarks-utils.mjs'
3import functionToBench from './functions/function-to-bench.js'
4
5const size = parseInt(process.env.POOL_SIZE)
6const iterations = parseInt(process.env.NUM_ITERATIONS)
7const data = {
8 test: 'MYBENCH',
9 taskType: process.env.TASK_TYPE,
10 taskSize: parseInt(process.env.TASK_SIZE)
11}
12
13const dynamicPool = new DynamicPool(size)
14
15async function run () {
16 const promises = new Set()
17 for (let i = 0; i < iterations; i++) {
18 promises.add(
19 dynamicPool.exec({
20 task: functionToBench,
21 param: data,
22 timeout: 60000 // this is the same as poolifier default
23 })
24 )
25 }
26 await Promise.all(promises)
27 // eslint-disable-next-line n/no-process-exit
28 process.exit()
29}
30
31await executeAsyncFn(run)