From bd0e5c4dda309d307e83ddfd8a974df631fc21da Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 10 May 2021 10:24:02 +0200 Subject: [PATCH] Update threads pool libraries to benchmark to latest. (#334) Co-authored-by: Shinigami --- benchmarks/README.md | 5 ++- .../versus-external-pools/BENCH-100000.md | 22 +++++++----- benchmarks/versus-external-pools/bench.sh | 35 +++++++++--------- .../fixed-worker-threads-pool.js | 24 ++++++++----- .../hyperfine_benchmarks.sh | 18 ++++++++++ .../versus-external-pools/package-lock.json | 36 ++++++++----------- benchmarks/versus-external-pools/package.json | 6 ++-- 7 files changed, 84 insertions(+), 62 deletions(-) create mode 100755 benchmarks/versus-external-pools/hyperfine_benchmarks.sh diff --git a/benchmarks/README.md b/benchmarks/README.md index 4059359a..66b7abb2 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -19,12 +19,11 @@ External pools with which we compared the poolifier results: - [workerpool](https://github.com/josdejong/workerpool) - [threadwork](https://github.com/kevlened/threadwork) - [microjob](https://github.com/wilk/microjob) -- [worker-threads-pool](https://github.com/watson/worker-threads-pool) + Those are our results: -- CPU Intensive task with 100k operations submitted to each pool [BENCH-100000.md](./versus-external-pools/BENCH-100000.md). - This benchmark ran on a MacBook Pro 2015, 2,2 GHz Intel Core i7 quad-core, 16 GB 1600 MHz DDR3. +- CPU Intensive task with 100k operations submitted to each pool [BENCH-100000.md](./versus-external-pools/BENCH-100000.md). > :warning: **We would need funds to run our benchmarks more often and on Cloud VMs, please consider to sponsor this project** diff --git a/benchmarks/versus-external-pools/BENCH-100000.md b/benchmarks/versus-external-pools/BENCH-100000.md index 5aa5adad..5fed6586 100644 --- a/benchmarks/versus-external-pools/BENCH-100000.md +++ b/benchmarks/versus-external-pools/BENCH-100000.md @@ -1,9 +1,13 @@ -| Command | Mean [s] | Min [s] | Max [s] | Relative | -| :--------------------------------------------------- | --------------: | ------: | ------: | ----------: | -| `node dynamic-piscina.js` | 47.192 ± 0.607 | 46.774 | 48.804 | 1.07 ± 0.01 | -| `node fixed-piscina.js` | 47.046 ± 0.112 | 46.823 | 47.178 | 1.07 ± 0.00 | -| `node dynamic-poolifier.js` | 44.301 ± 0.989 | 43.718 | 46.994 | 1.00 ± 0.02 | -| `node fixed-poolifier.js` | 44.115 ± 0.174 | 43.843 | 44.510 | 1.00 | -| `node static-suchmokuo-node-worker-threads-pool.js` | 48.282 ± 1.857 | 46.361 | 50.268 | 1.09 ± 0.04 | -| `node dynamic-suchmokuo-node-worker-threads-pool.js` | 60.111 ± 2.401 | 57.752 | 63.011 | 1.36 ± 0.05 | -| `node threadjs.js` | 131.412 ± 4.210 | 122.872 | 138.506 | 2.98 ± 0.10 | +| Command | Mean [s] | Min [s] | Max [s] | Relative | +|:-----------------------------------------------------|---------------:|--------:|--------:|------------:| +| `node dynamic-piscina.js` | 18.364 ± 0.203 | 18.050 | 18.737 | 1.07 ± 0.02 | +| `node fixed-piscina.js` | 18.222 ± 0.519 | 17.529 | 19.164 | 1.06 ± 0.03 | +| `node dynamic-poolifier.js` | 17.135 ± 0.256 | 16.926 | 17.755 | 1.00 | +| `node fixed-poolifier.js` | 17.947 ± 0.489 | 17.567 | 18.951 | 1.05 ± 0.03 | +| `node dynamic-suchmokuo-node-worker-threads-pool.js` | 25.460 ± 0.453 | 25.124 | 26.617 | 1.49 ± 0.03 | +| `node static-suchmokuo-node-worker-threads-pool.js` | 18.993 ± 0.714 | 18.388 | 20.610 | 1.11 ± 0.04 | +| `node threadjs.js` | 80.939 ± 3.548 | 76.881 | 88.363 | 4.72 ± 0.22 | +| `node dynamic-workerpool.js` | 19.292 ± 0.110 | 19.109 | 19.480 | 1.13 ± 0.02 | +| `node fixed-workerpool.js` | 19.684 ± 0.636 | 19.212 | 21.049 | 1.15 ± 0.04 | +| `node fixed-threadwork.js` | 30.023 ± 0.362 | 29.524 | 30.727 | 1.75 ± 0.03 | +| `node fixed-microjob.js` | 32.526 ± 0.649 | 31.696 | 33.687 | 1.90 ± 0.05 | diff --git a/benchmarks/versus-external-pools/bench.sh b/benchmarks/versus-external-pools/bench.sh index 94c5a3b5..f78500f7 100755 --- a/benchmarks/versus-external-pools/bench.sh +++ b/benchmarks/versus-external-pools/bench.sh @@ -1,12 +1,16 @@ +#!/usr/bin/env bash + ### The -t argument is needed to specify the type of task that you want to benchmark. ### Supported values are CPU_INTENSIVE taskType='CPU_INTENSIVE' while getopts t: flag do - case "${flag}" in - t) taskType=${OPTARG};; - esac + case "${flag}" in + t) + taskType=${OPTARG} + ;; + esac done echo 'Running bench for task type:' $taskType @@ -15,17 +19,14 @@ export TASK_TYPE=$taskType export NODE_ENV=production export POOL_SIZE=10 export NUM_ITERATIONS=100000 -hyperfine --export-markdown BENCH-100000.md --min-runs 10 \ - --prepare 'sleep 15' \ - 'node dynamic-piscina.js' \ - 'node fixed-piscina.js' \ - 'node dynamic-poolifier.js' \ - 'node fixed-poolifier.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-worker-threads-pool.js' +case "$OSTYPE" in + darwin*) + caffeinate ./hyperfine_benchmarks.sh + ;; + linux*) + systemd-inhibit ./hyperfine_benchmarks.sh + ;; + *) + echo "Unsupported $OSTYPE" + ;; +esac diff --git a/benchmarks/versus-external-pools/fixed-worker-threads-pool.js b/benchmarks/versus-external-pools/fixed-worker-threads-pool.js index ed7e2ae1..b4d9eced 100644 --- a/benchmarks/versus-external-pools/fixed-worker-threads-pool.js +++ b/benchmarks/versus-external-pools/fixed-worker-threads-pool.js @@ -10,17 +10,25 @@ const data = { const pool = new Pool({ max: size }) +async function poolAcquireAsync () { + return new Promise((resolve, reject) => { + pool.acquire( + './workers/worker-threads-pool/function-to-bench-worker.js', + { + workerData: data + }, + err => { + if (err) reject(err) + resolve() + } + ) + }) +} + async function run () { const promises = [] for (let i = 0; i < iterations; i++) { - promises.push( - pool.acquire( - './workers/worker-threads-pool/function-to-bench-worker.js', - { - workerData: data - } - ) - ) + promises.push(poolAcquireAsync()) } await Promise.all(promises) process.exit() diff --git a/benchmarks/versus-external-pools/hyperfine_benchmarks.sh b/benchmarks/versus-external-pools/hyperfine_benchmarks.sh new file mode 100755 index 00000000..7ab3bf3f --- /dev/null +++ b/benchmarks/versus-external-pools/hyperfine_benchmarks.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +hyperfine --export-markdown BENCH-100000.md --min-runs 10 \ + --prepare 'sleep 15' \ + 'node dynamic-piscina.js' \ + 'node fixed-piscina.js' \ + 'node dynamic-poolifier.js' \ + 'node fixed-poolifier.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-worker-threads-pool.js' + + diff --git a/benchmarks/versus-external-pools/package-lock.json b/benchmarks/versus-external-pools/package-lock.json index 43eb15f3..a9239362 100644 --- a/benchmarks/versus-external-pools/package-lock.json +++ b/benchmarks/versus-external-pools/package-lock.json @@ -71,12 +71,9 @@ "integrity": "sha512-7kIufnBqdsBGcSZLPJwqHT3yhk1QTsSlFsVD3kx5ixH/AlgBs9yM1q6DPhXZ8f8gtdqgh7N7/5btRLpQsS2gHw==" }, "is-observable": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-observable/-/is-observable-1.1.0.tgz", - "integrity": "sha512-NqCa4Sa2d+u7BWc6CukaObG3Fh+CU9bvixbpcXYhy2VvYS7vVGIdAgnIS5Ks3A/cqk4rebLJ9s8zBstT2aKnIA==", - "requires": { - "symbol-observable": "^1.1.0" - } + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-observable/-/is-observable-2.1.0.tgz", + "integrity": "sha512-DailKdLb0WU+xX8K5w7VsJhapwHLZ9jjmazqCJq4X12CTgqq73TKnbRcnSLuXYPOoLQgV5IrD7ePiX/h1vnkBw==" }, "locate-path": { "version": "6.0.0", @@ -163,9 +160,9 @@ "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==" }, "piscina": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/piscina/-/piscina-2.2.0.tgz", - "integrity": "sha512-CQb0DfyTdC9FBIMYkVV/00fXRLKDjmWKA8S0N1zDg2JGEc5z3P9qHXtoq8OkJQ+vjCfXySkVonTNMqskMFOW/w==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/piscina/-/piscina-3.0.0.tgz", + "integrity": "sha512-ye56YiBCK3loPGsagK/Sf/aeuCPAkvZIJDGQnv+SSOQUz1Od5cUsDeirQBB0cxFkXCY6FDsk36Z9xX1D2Zb8Zw==", "requires": { "eventemitter-asyncresource": "^1.0.0", "hdr-histogram-js": "^2.0.1", @@ -186,19 +183,14 @@ "resolved": "https://registry.npmjs.org/poolifier/-/poolifier-2.0.1.tgz", "integrity": "sha512-klkLv35QVumXKrQj6Totvwqb0lw34j7mIsEm8uZXXHlcpVCvnhhgVFVyuZUOSNTjZnBCaiB0KcLos03cqj38CA==" }, - "symbol-observable": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.2.0.tgz", - "integrity": "sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==" - }, "threads": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/threads/-/threads-1.6.3.tgz", - "integrity": "sha512-tKwFIWRgfAT85KGkrpDt2jWPO8IVH0sLNfB/pXad/VW9eUIY2Zlz+QyeizypXhPHv9IHfqRzvk2t3mPw+imhWw==", + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/threads/-/threads-1.6.4.tgz", + "integrity": "sha512-A+9MQFAUha9W8MjIPmrvETy98qVmZFr5Unox9D95y7kvz3fBpGiFS7JOZs07B2KvTHoRNI5MrGudRVeCmv4Alw==", "requires": { "callsites": "^3.1.0", - "debug": "^4.1.1", - "is-observable": "^1.1.0", + "debug": "^4.2.0", + "is-observable": "^2.1.0", "observable-fns": "^0.5.1", "tiny-worker": ">= 2" } @@ -230,9 +222,9 @@ } }, "workerpool": { - "version": "6.1.2", - "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.1.2.tgz", - "integrity": "sha512-I/gDW4LwV3bslk4Yiqd4XoNYlnvV03LON7KuIjmQ90yDnKND1sR2LK/JA1g1tmd71oe6KPSvN0JpBzXIH6xAgA==" + "version": "6.1.4", + "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.1.4.tgz", + "integrity": "sha512-jGWPzsUqzkow8HoAvqaPWTUPCrlPJaJ5tY8Iz7n1uCz3tTp6s3CDG0FF1NsX42WNlkRSW6Mr+CDZGnNoSsKa7g==" }, "wrappy": { "version": "1.0.2", diff --git a/benchmarks/versus-external-pools/package.json b/benchmarks/versus-external-pools/package.json index 0a0166b8..a3b7f0ef 100644 --- a/benchmarks/versus-external-pools/package.json +++ b/benchmarks/versus-external-pools/package.json @@ -11,11 +11,11 @@ "dependencies": { "microjob": "0.7.0", "node-worker-threads-pool": "1.4.3", - "piscina": "2.2.0", + "piscina": "3.0.0", "poolifier": "2.0.1", - "threads": "1.6.3", + "threads": "1.6.4", "threadwork": "0.6.0", "worker-threads-pool": "2.0.0", - "workerpool": "6.1.2" + "workerpool": "6.1.4" } } -- 2.34.1