From 6c06373320e61af1078a265851a15711a97b08af Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 17 Oct 2022 18:23:50 +0200 Subject: [PATCH] Initial worker-nodes integration in benchmarks. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Seems to have scalability issue with our workload Reference #106 Signed-off-by: Jérôme Benoit --- .../dynamic-worker-nodes.js | 29 +++++++++++++++++++ .../fixed-worker-nodes.js | 29 +++++++++++++++++++ .../functions/function-to-bench.js | 24 ++++++++------- .../hyperfine_benchmarks.sh | 16 ++++++---- .../versus-external-pools/package-lock.json | 14 +++++++++ benchmarks/versus-external-pools/package.json | 1 + .../worker-nodes/function-to-bench-worker.js | 3 ++ 7 files changed, 100 insertions(+), 16 deletions(-) create mode 100644 benchmarks/versus-external-pools/dynamic-worker-nodes.js create mode 100644 benchmarks/versus-external-pools/fixed-worker-nodes.js create mode 100644 benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.js 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 } -- 2.34.1