--- /dev/null
+// IMPORT LIBRARIES
+const WorkerNodes = require('worker-nodes')
+// FINISH IMPORT LIBRARIES
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
+const data = {
+ test: 'MYBENCH',
+ taskType: process.env['TASK_TYPE']
+}
+
+const workerNodes = new WorkerNodes(
+ require.resolve('./workers/worker-nodes/function-to-bench-worker'),
+ {
+ minWorkers: size,
+ maxWorkers: size * 3,
+ taskTimeout: 60000 // this is the same as poolifier default
+ }
+)
+
+async function run () {
+ const promises = []
+ for (let i = 0; i < iterations; i++) {
+ promises.push(workerNodes.call.functionToBench(data))
+ }
+ await Promise.all(promises)
+ process.exit()
+}
+
+run()
--- /dev/null
+// IMPORT LIBRARIES
+const WorkerNodes = require('worker-nodes')
+// FINISH IMPORT LIBRARIES
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
+const data = {
+ test: 'MYBENCH',
+ taskType: process.env['TASK_TYPE']
+}
+
+const workerNodes = new WorkerNodes(
+ require.resolve('./workers/worker-nodes/function-to-bench-worker'),
+ {
+ minWorkers: size,
+ maxWorkers: size,
+ taskTimeout: 60000 // this is the same as poolifier default
+ }
+)
+
+async function run () {
+ const promises = []
+ for (let i = 0; i < iterations; i++) {
+ promises.push(workerNodes.call.functionToBench(data))
+ }
+ await Promise.all(promises)
+ process.exit()
+}
+
+run()
module.exports = function (data) {
- if (data.taskType === 'CPU_INTENSIVE') {
- // CPU intensive task
- for (let i = 0; i < 5000; i++) {
- const o = {
- a: i
+ data = data || {}
+ data.taskType = data.taskType || 'CPU_INTENSIVE'
+ data.taskSize = data.taskSize || 5000
+ switch (data.taskType) {
+ case 'CPU_INTENSIVE':
+ // CPU intensive task
+ for (let i = 0; i < data.taskSize; i++) {
+ const o = {
+ a: i
+ }
+ JSON.stringify(o)
}
- JSON.stringify(o)
- }
- return { ok: 1 }
- } else {
- throw new Error('Please specify the task type')
+ return { ok: 1 }
+ default:
+ throw new Error(`Unknown task type: ${data.taskType}`)
}
}
#!/usr/bin/env bash
-hyperfine --export-markdown BENCH-100000.md --min-runs 10 \
+hyperfine --export-markdown BENCH-100000.md --min-runs 10 --show-output \
--prepare 'sleep 15' \
- 'node dynamic-piscina.js' \
- 'node fixed-piscina.js' \
'node dynamic-poolifier.js' \
'node fixed-poolifier.js' \
+ 'node dynamic-piscina.js' \
+ 'node fixed-piscina.js' \
+ 'node dynamic-workerpool.js' \
+ 'node fixed-workerpool.js' \
'node dynamic-suchmokuo-node-worker-threads-pool.js' \
'node static-suchmokuo-node-worker-threads-pool.js' \
'node threadjs.js' \
- 'node dynamic-workerpool.js' \
- 'node fixed-workerpool.js' \
'node fixed-threadwork.js' \
- 'node fixed-microjob.js'
+ 'node fixed-microjob.js' \
+ # Seems to have scalability issues, disabled for now
+ # 'node dynamic-worker-nodes.js' \
+ # 'node fixed-worker-nodes.js'
+
"poolifier": "2.3.3",
"threads": "1.7.0",
"threadwork": "0.6.0",
+ "worker-nodes": "2.4.0",
"workerpool": "6.2.1"
}
},
"esm": "^3.2.25"
}
},
+ "node_modules/worker-nodes": {
+ "version": "2.4.0",
+ "resolved": "https://registry.npmjs.org/worker-nodes/-/worker-nodes-2.4.0.tgz",
+ "integrity": "sha512-s32ziQpiWkWbB/ziFKiudpm5/mreSnwpTtKzPxgcPXpl+kXpesiibjM/2Z8i/lDO8kDCUio7wQFXtndopgfsUg==",
+ "engines": {
+ "node": ">=11.7.0"
+ }
+ },
"node_modules/workerpool": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz",
"esm": "^3.2.25"
}
},
+ "worker-nodes": {
+ "version": "2.4.0",
+ "resolved": "https://registry.npmjs.org/worker-nodes/-/worker-nodes-2.4.0.tgz",
+ "integrity": "sha512-s32ziQpiWkWbB/ziFKiudpm5/mreSnwpTtKzPxgcPXpl+kXpesiibjM/2Z8i/lDO8kDCUio7wQFXtndopgfsUg=="
+ },
"workerpool": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz",
"poolifier": "2.3.3",
"threads": "1.7.0",
"threadwork": "0.6.0",
+ "worker-nodes": "2.4.0",
"workerpool": "6.2.1"
}
}
--- /dev/null
+'use strict'
+const functionToBench = require('../../functions/function-to-bench')
+module.exports = { functionToBench }