From: Jérôme Benoit Date: Mon, 19 Jun 2023 12:08:01 +0000 (+0200) Subject: docs: add tinypool to external pools benchmark X-Git-Tag: v2.6.3~8 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=935f9dbfab43a61ffa756313e6088adc2261a79d;p=poolifier.git docs: add tinypool to external pools benchmark Signed-off-by: Jérôme Benoit --- diff --git a/.vscode/settings.json b/.vscode/settings.json index 010c3dc3..1004671c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -41,6 +41,7 @@ "threadjs", "THREADPOOL", "threadwork", + "tinypool", "trimmable", "tsdoc", "typedoc", diff --git a/benchmarks/versus-external-pools/dynamic-tinypool.mjs b/benchmarks/versus-external-pools/dynamic-tinypool.mjs new file mode 100644 index 00000000..18e3866b --- /dev/null +++ b/benchmarks/versus-external-pools/dynamic-tinypool.mjs @@ -0,0 +1,32 @@ +// IMPORT LIBRARIES +import Tinypool from 'tinypool' +// FINISH IMPORT LIBRARIES +const size = parseInt(process.env.POOL_SIZE) +const iterations = parseInt(process.env.NUM_ITERATIONS) +const data = { + test: 'MYBENCH', + taskType: process.env.TASK_TYPE, + taskSize: parseInt(process.env.TASK_SIZE) +} + +const tinypool = new Tinypool({ + filename: './workers/tinypool/function-to-bench-worker.js', + minThreads: size, + maxThreads: size * 3, + idleTimeout: 60000 // this is the same as poolifier default +}) + +/** + * + */ +async function run () { + const promises = [] + for (let i = 0; i < iterations; i++) { + promises.push(tinypool.run(data)) + } + await Promise.all(promises) + // eslint-disable-next-line n/no-process-exit + process.exit() +} + +run() diff --git a/benchmarks/versus-external-pools/fixed-tinypool.mjs b/benchmarks/versus-external-pools/fixed-tinypool.mjs new file mode 100644 index 00000000..223c0f00 --- /dev/null +++ b/benchmarks/versus-external-pools/fixed-tinypool.mjs @@ -0,0 +1,31 @@ +// IMPORT LIBRARIES +import Tinypool from 'tinypool' +// FINISH IMPORT LIBRARIES +const size = parseInt(process.env.POOL_SIZE) +const iterations = parseInt(process.env.NUM_ITERATIONS) +const data = { + test: 'MYBENCH', + taskType: process.env.TASK_TYPE, + taskSize: parseInt(process.env.TASK_SIZE) +} + +const tinypool = new Tinypool({ + filename: './workers/tinypool/function-to-bench-worker.js', + minThreads: size, + idleTimeout: 60000 // this is the same as poolifier default +}) + +/** + * + */ +async function run () { + const promises = [] + for (let i = 0; i < iterations; i++) { + promises.push(tinypool.run(data)) + } + await Promise.all(promises) + // eslint-disable-next-line n/no-process-exit + process.exit() +} + +run() diff --git a/benchmarks/versus-external-pools/hyperfine_benchmarks.sh b/benchmarks/versus-external-pools/hyperfine_benchmarks.sh index bddeb12e..9979c573 100755 --- a/benchmarks/versus-external-pools/hyperfine_benchmarks.sh +++ b/benchmarks/versus-external-pools/hyperfine_benchmarks.sh @@ -6,6 +6,8 @@ hyperfine --export-markdown BENCH-100000.md --min-runs 10 \ 'node fixed-poolifier.js' \ 'node dynamic-piscina.js' \ 'node fixed-piscina.js' \ + 'node fixed-tinypool.mjs' \ + 'node dynamic-tinypool.mjs' \ 'node dynamic-workerpool.js' \ 'node fixed-workerpool.js' \ 'node dynamic-suchmokuo-node-worker-threads-pool.js' \ diff --git a/benchmarks/versus-external-pools/package.json b/benchmarks/versus-external-pools/package.json index 294332c9..d1e5485f 100644 --- a/benchmarks/versus-external-pools/package.json +++ b/benchmarks/versus-external-pools/package.json @@ -23,6 +23,7 @@ "poolifier": "2.6.2", "threads": "1.7.0", "threadwork": "0.6.0", + "tinypool": "0.5.0", "worker-nodes": "2.5.0", "workerpool": "6.4.0" } diff --git a/benchmarks/versus-external-pools/pnpm-lock.yaml b/benchmarks/versus-external-pools/pnpm-lock.yaml index 62fd7f56..08d34f4f 100644 --- a/benchmarks/versus-external-pools/pnpm-lock.yaml +++ b/benchmarks/versus-external-pools/pnpm-lock.yaml @@ -23,6 +23,9 @@ dependencies: threadwork: specifier: 0.6.0 version: 0.6.0 + tinypool: + specifier: 0.5.0 + version: 0.5.0 worker-nodes: specifier: 2.5.0 version: 2.5.0 @@ -212,6 +215,11 @@ packages: dev: false optional: true + /tinypool@0.5.0: + resolution: {integrity: sha512-paHQtnrlS1QZYKF/GnLoOM/DN9fqaGOFbCbxzAhwniySnzl9Ebk8w73/dd34DAhe/obUbPAOldTyYXQZxnPBPQ==} + engines: {node: '>=14.0.0'} + dev: false + /worker-nodes@2.5.0: resolution: {integrity: sha512-0hPZfN21PkMMeljxvFa2+MqOAItvwWnQYMUG6HGhM0X1rTlXPAgVFY+IH4UQC/TmSi/3qMIDdrxArRR8dEdQcQ==} engines: {node: '>=11.7.0'} diff --git a/benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.js new file mode 100644 index 00000000..9fa8b472 --- /dev/null +++ b/benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.js @@ -0,0 +1,3 @@ +'use strict' +const functionToBench = require('../../functions/function-to-bench') +module.exports = functionToBench