-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic-worker-nodes.cjs
More file actions
37 lines (33 loc) · 1006 Bytes
/
dynamic-worker-nodes.cjs
File metadata and controls
37 lines (33 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict'
const WorkerNodes = require('worker-nodes')
const { BenchmarkDefaults, executeAsyncFn } = require('./utils.cjs')
const size =
Number.parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
const numIterations =
Number.parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const data = {
taskSize:
Number.parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize,
taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
test: 'MYBENCH',
}
const workerNodes = new WorkerNodes(require.resolve('./functions/index.cjs'), {
maxWorkers: size,
minWorkers: Math.floor(size / 2),
taskTimeout: BenchmarkDefaults.idleTimeout,
})
/**
*
*/
const run = async () => {
const promises = new Set()
for (let i = 0; i < numIterations; i++) {
promises.add(workerNodes.call.functionToBench(data))
}
await Promise.all(promises)
// eslint-disable-next-line n/no-process-exit
process.exit()
}
;(async () => {
await executeAsyncFn(run)
})()