From 02749105fad5c3de792acbe23ed8dae1915ba2aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 4 Jul 2023 14:07:43 +0200 Subject: [PATCH] fix: properly size the pools in benchmarking code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .vscode/settings.json | 1 + benchmarks/benchmarks-utils.mjs | 4 ++-- benchmarks/versus-external-pools/bench.sh | 2 +- benchmarks/versus-external-pools/dynamic-piscina.mjs | 4 ++-- benchmarks/versus-external-pools/dynamic-poolifier.mjs | 2 +- benchmarks/versus-external-pools/dynamic-tinypool.mjs | 4 ++-- benchmarks/versus-external-pools/dynamic-worker-nodes.js | 4 ++-- benchmarks/versus-external-pools/dynamic-workerpool.mjs | 4 ++-- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 20e48e2d..867b65ff 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,6 +25,7 @@ "mochawesome", "MYBENCH", "nocombine", + "nproc", "octocat", "opencollective", "OPTARG", diff --git a/benchmarks/benchmarks-utils.mjs b/benchmarks/benchmarks-utils.mjs index 56767597..48d5e41b 100644 --- a/benchmarks/benchmarks-utils.mjs +++ b/benchmarks/benchmarks-utils.mjs @@ -134,14 +134,14 @@ export const buildPool = (workerType, poolType, poolSize, poolOptions) => { case WorkerTypes.thread: return new DynamicThreadPool( Math.floor(poolSize / 2), - poolSize * 3, + poolSize, './benchmarks/internal/thread-worker.mjs', poolOptions ) case WorkerTypes.cluster: return new DynamicClusterPool( Math.floor(poolSize / 2), - poolSize * 3, + poolSize, './benchmarks/internal/cluster-worker.mjs', poolOptions ) diff --git a/benchmarks/versus-external-pools/bench.sh b/benchmarks/versus-external-pools/bench.sh index e1790aea..7221ba32 100755 --- a/benchmarks/versus-external-pools/bench.sh +++ b/benchmarks/versus-external-pools/bench.sh @@ -37,7 +37,7 @@ done taskType=${taskType:-'CPU_INTENSIVE'} taskSize=${taskSize:-5000} -poolSize=${poolSize:-10} +poolSize=${poolSize:-$(nproc --all)} iterations=${iterations:-100000} echo 'Running benchmarks with pool size:' ${poolSize}', number of iterations:' ${iterations}', task type:' ${taskType} 'and task size:' ${taskSize} diff --git a/benchmarks/versus-external-pools/dynamic-piscina.mjs b/benchmarks/versus-external-pools/dynamic-piscina.mjs index 6fcc6793..a1e425f8 100644 --- a/benchmarks/versus-external-pools/dynamic-piscina.mjs +++ b/benchmarks/versus-external-pools/dynamic-piscina.mjs @@ -11,8 +11,8 @@ const data = { const piscina = new Piscina({ filename: './workers/piscina/function-to-bench-worker.mjs', - minThreads: size, - maxThreads: size * 3, + minThreads: Math.floor(size / 2), + maxThreads: size, idleTimeout: 60000 // this is the same as poolifier default }) diff --git a/benchmarks/versus-external-pools/dynamic-poolifier.mjs b/benchmarks/versus-external-pools/dynamic-poolifier.mjs index 34adba05..48d3028f 100644 --- a/benchmarks/versus-external-pools/dynamic-poolifier.mjs +++ b/benchmarks/versus-external-pools/dynamic-poolifier.mjs @@ -10,8 +10,8 @@ const data = { } const dynamicPool = new DynamicThreadPool( + Math.floor(size / 2), size, - size * 3, './workers/poolifier/function-to-bench-worker.mjs' ) diff --git a/benchmarks/versus-external-pools/dynamic-tinypool.mjs b/benchmarks/versus-external-pools/dynamic-tinypool.mjs index a28de9b5..acb8627f 100644 --- a/benchmarks/versus-external-pools/dynamic-tinypool.mjs +++ b/benchmarks/versus-external-pools/dynamic-tinypool.mjs @@ -11,8 +11,8 @@ const data = { const tinypool = new Tinypool({ filename: './workers/tinypool/function-to-bench-worker.mjs', - minThreads: size, - maxThreads: size * 3, + minThreads: Math.floor(size / 2), + maxThreads: size, idleTimeout: 60000 // this is the same as poolifier default }) diff --git a/benchmarks/versus-external-pools/dynamic-worker-nodes.js b/benchmarks/versus-external-pools/dynamic-worker-nodes.js index 6a55aaf9..17255ba2 100644 --- a/benchmarks/versus-external-pools/dynamic-worker-nodes.js +++ b/benchmarks/versus-external-pools/dynamic-worker-nodes.js @@ -13,8 +13,8 @@ const data = { const workerNodes = new WorkerNodes( require.resolve('./workers/worker-nodes/function-to-bench-worker'), { - minWorkers: size, - maxWorkers: size * 3, + minWorkers: Math.floor(size / 2), + maxWorkers: size, taskTimeout: 60000 // this is the same as poolifier default } ) diff --git a/benchmarks/versus-external-pools/dynamic-workerpool.mjs b/benchmarks/versus-external-pools/dynamic-workerpool.mjs index 072aa6fd..9dc0e702 100644 --- a/benchmarks/versus-external-pools/dynamic-workerpool.mjs +++ b/benchmarks/versus-external-pools/dynamic-workerpool.mjs @@ -12,8 +12,8 @@ const dataArray = [ const workerPool = workerpool.pool( './workers/workerpool/function-to-bench-worker.mjs', { - minWorkers: size, - maxWorkers: size * 3, + minWorkers: Math.floor(size / 2), + maxWorkers: size, workerType: 'thread' } ) -- 2.34.1