From: Jérôme Benoit Date: Mon, 17 Oct 2022 16:23:50 +0000 (+0200) Subject: Initial worker-nodes integration in benchmarks. X-Git-Tag: v2.3.5~20 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=6c06373320e61af1078a265851a15711a97b08af;p=poolifier.git Initial worker-nodes integration in benchmarks. Seems to have scalability issue with our workload Reference #106 Signed-off-by: Jérôme Benoit --- diff --git a/benchmarks/versus-external-pools/dynamic-worker-nodes.js b/benchmarks/versus-external-pools/dynamic-worker-nodes.js new file mode 100644 index 00000000..6b860d5f --- /dev/null +++ b/benchmarks/versus-external-pools/dynamic-worker-nodes.js @@ -0,0 +1,29 @@ +// 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() diff --git a/benchmarks/versus-external-pools/fixed-worker-nodes.js b/benchmarks/versus-external-pools/fixed-worker-nodes.js new file mode 100644 index 00000000..58965d21 --- /dev/null +++ b/benchmarks/versus-external-pools/fixed-worker-nodes.js @@ -0,0 +1,29 @@ +// 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() diff --git a/benchmarks/versus-external-pools/functions/function-to-bench.js b/benchmarks/versus-external-pools/functions/function-to-bench.js index 565f8112..b9054db2 100644 --- a/benchmarks/versus-external-pools/functions/function-to-bench.js +++ b/benchmarks/versus-external-pools/functions/function-to-bench.js @@ -1,14 +1,18 @@ 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}`) } } diff --git a/benchmarks/versus-external-pools/hyperfine_benchmarks.sh b/benchmarks/versus-external-pools/hyperfine_benchmarks.sh index 1ac1beda..b866bb8b 100755 --- a/benchmarks/versus-external-pools/hyperfine_benchmarks.sh +++ b/benchmarks/versus-external-pools/hyperfine_benchmarks.sh @@ -1,17 +1,21 @@ #!/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' + diff --git a/benchmarks/versus-external-pools/package-lock.json b/benchmarks/versus-external-pools/package-lock.json index 0dce8f65..77e7497e 100644 --- a/benchmarks/versus-external-pools/package-lock.json +++ b/benchmarks/versus-external-pools/package-lock.json @@ -14,6 +14,7 @@ "poolifier": "2.3.3", "threads": "1.7.0", "threadwork": "0.6.0", + "worker-nodes": "2.4.0", "workerpool": "6.2.1" } }, @@ -301,6 +302,14 @@ "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", @@ -512,6 +521,11 @@ "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", diff --git a/benchmarks/versus-external-pools/package.json b/benchmarks/versus-external-pools/package.json index fe74923a..10e566b2 100644 --- a/benchmarks/versus-external-pools/package.json +++ b/benchmarks/versus-external-pools/package.json @@ -15,6 +15,7 @@ "poolifier": "2.3.3", "threads": "1.7.0", "threadwork": "0.6.0", + "worker-nodes": "2.4.0", "workerpool": "6.2.1" } } diff --git a/benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.js new file mode 100644 index 00000000..b9a9ea26 --- /dev/null +++ b/benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.js @@ -0,0 +1,3 @@ +'use strict' +const functionToBench = require('../../functions/function-to-bench') +module.exports = { functionToBench }