- [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)
+<!-- - [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**
-| 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 |
+#!/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
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
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()
--- /dev/null
+#!/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'
+
+
"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",
"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",
"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"
}
}
},
"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",
"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"
}
}