From 7f6850931df7ba1410c8c167ab03b2f089bc32dd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 12 Mar 2021 20:11:02 +0100 Subject: [PATCH] Add threadwork, microjob to external pools benchmark (#266) --- CHANGELOG.md | 9 +++++- benchmarks/README.md | 3 ++ benchmarks/versus-external-pools/bench.sh | 4 ++- .../versus-external-pools/fixed-microjob.js | 31 +++++++++++++++++++ .../versus-external-pools/fixed-threadwork.js | 25 +++++++++++++++ 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 benchmarks/versus-external-pools/fixed-microjob.js create mode 100644 benchmarks/versus-external-pools/fixed-threadwork.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 211ade56..e1688efb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.0.x] - yyyy-dd-mm + +### Bug fixes + +- Check if pool options are properly set. +- `busy` event is emitted on all pool types. + ## [2.0.0] - 2021-01-03 ### Bug fixes @@ -13,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking Changes -- `FullPool` event is now renamed to `busy` and emitted on all pool types. +- `FullPool` event is now renamed to `busy`. - `maxInactiveTime` on `ThreadWorker` default behavior is now changed, if you want to keep the old behavior set `killBehavior` to `KillBehaviors.HARD`. _Find more details on our JSDoc._ diff --git a/benchmarks/README.md b/benchmarks/README.md index 61b57518..bdec9bf2 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -16,6 +16,9 @@ External pools with which we compared the poolifier results: - [piscina](https://github.com/piscinajs/piscina) - [SUCHMOKUO/node-worker-threads-pool](https://github.com/SUCHMOKUO/node-worker-threads-pool) - [threads.js](https://github.com/andywer/threads.js/) +- [workerpool](https://github.com/josdejong/workerpool) +- [threadwork](https://github.com/kevlened/threadwork) +- [microjob](https://github.com/wilk/microjob) Those are our results: diff --git a/benchmarks/versus-external-pools/bench.sh b/benchmarks/versus-external-pools/bench.sh index ae5b76ee..d3f51216 100755 --- a/benchmarks/versus-external-pools/bench.sh +++ b/benchmarks/versus-external-pools/bench.sh @@ -25,4 +25,6 @@ hyperfine --export-markdown BENCH-100000.md --min-runs 10 \ 'node static-suchmokuo-node-worker-threads-pool.js' \ 'node threadjs.js' \ 'node dynamic-workerpool.js' \ - 'node fixed-workerpool.js' + 'node fixed-workerpool.js' \ + 'node fixed-threadwork.js' \ + 'node fixed-microjob.js' diff --git a/benchmarks/versus-external-pools/fixed-microjob.js b/benchmarks/versus-external-pools/fixed-microjob.js new file mode 100644 index 00000000..4bc64da9 --- /dev/null +++ b/benchmarks/versus-external-pools/fixed-microjob.js @@ -0,0 +1,31 @@ +// IMPORT LIBRARIES +const { job, start } = require('microjob') +// FINISH IMPORT LIBRARIES +// IMPORT FUNCTION TO BENCH +const functionToBench = require('./functions/function-to-bench') +// FINISH IMPORT FUNCTION TO BENCH +const size = process.env.POOL_SIZE +const iterations = process.env.NUM_ITERATIONS +const data = { + test: 'MYBENCH', + taskType: process.env['TASK_TYPE'] +} + +async function run () { + await start({ maxWorkers: Number(size) }) + const promises = [] + for (let i = 0; i < iterations; i++) { + promises.push( + job( + data => { + functionToBench(data) + }, + { data: data, ctx: { functionToBench } } + ) + ) + } + await Promise.all(promises) + process.exit() +} + +run() diff --git a/benchmarks/versus-external-pools/fixed-threadwork.js b/benchmarks/versus-external-pools/fixed-threadwork.js new file mode 100644 index 00000000..dfba6c00 --- /dev/null +++ b/benchmarks/versus-external-pools/fixed-threadwork.js @@ -0,0 +1,25 @@ +// IMPORT LIBRARIES +const { ThreadPool } = require('threadwork') +// FINISH IMPORT LIBRARIES +// IMPORT FUNCTION TO BENCH +const functionToBench = require('./functions/function-to-bench') +// FINISH IMPORT FUNCTION TO BENCH +const size = process.env.POOL_SIZE +const iterations = process.env.NUM_ITERATIONS +const data = { + test: 'MYBENCH', + taskType: process.env['TASK_TYPE'] +} + +const threadPool = new ThreadPool({ task: functionToBench, size: size }) + +async function run () { + const promises = [] + for (let i = 0; i < iterations; i++) { + promises.push(threadPool.run(data)) + } + await Promise.all(promises) + process.exit() +} + +run() -- 2.34.1