Add worker-threads-pool to external pools benchmarks (#281)
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 19 Mar 2021 20:41:11 +0000 (21:41 +0100)
committerGitHub <noreply@github.com>
Fri, 19 Mar 2021 20:41:11 +0000 (21:41 +0100)
18 files changed:
benchmarks/README.md
benchmarks/versus-external-pools/bench.sh
benchmarks/versus-external-pools/dynamic-piscina.js
benchmarks/versus-external-pools/dynamic-poolifier.js
benchmarks/versus-external-pools/dynamic-suchmokuo-node-worker-threads-pool.js
benchmarks/versus-external-pools/dynamic-workerpool.js
benchmarks/versus-external-pools/fixed-microjob.js
benchmarks/versus-external-pools/fixed-piscina.js
benchmarks/versus-external-pools/fixed-poolifier.js
benchmarks/versus-external-pools/fixed-threadwork.js
benchmarks/versus-external-pools/fixed-worker-threads-pool.js [new file with mode: 0644]
benchmarks/versus-external-pools/fixed-workerpool.js
benchmarks/versus-external-pools/package-lock.json
benchmarks/versus-external-pools/package.json
benchmarks/versus-external-pools/static-suchmokuo-node-worker-threads-pool.js
benchmarks/versus-external-pools/threadjs.js
benchmarks/versus-external-pools/workers/worker-threads-pool/function-to-bench-worker.js [new file with mode: 0644]
package-lock.json

index bdec9bf225305dea2cad104cbdf29f2cb31ff7cd..4059359a8a5ee08960f151430d9321022a2453b0 100644 (file)
@@ -19,6 +19,7 @@ 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:
 
index d3f512165ad73561f5211d4e1245c403e9b2d6d6..94c5a3b5e3f7a68053fce69fd4376f48e7bb62cd 100755 (executable)
@@ -27,4 +27,5 @@ hyperfine --export-markdown BENCH-100000.md --min-runs 10 \
   'node dynamic-workerpool.js' \
   'node fixed-workerpool.js' \
   'node fixed-threadwork.js' \
-  'node fixed-microjob.js'
+  'node fixed-microjob.js' \
+  'node fixed-worker-threads-pool.js'
index 0881d1d051c9f69914c8ff300e69c30e843166a2..d78dd568c2c28ae9a9f0fd04d79e4e9c1ecd774e 100644 (file)
@@ -1,8 +1,8 @@
 // IMPORT LIBRARIES
 const Piscina = require('piscina')
 // FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env['TASK_TYPE']
@@ -10,7 +10,7 @@ const data = {
 
 const piscina = new Piscina({
   filename: './workers/piscina/function-to-bench-worker.js',
-  minThreads: Number(size),
+  minThreads: size,
   maxThreads: size * 3,
   idleTimeout: 1000 * 60 // this is the same as poolifier default
 })
index b20082a3541dfc9237c311a6c07c831fbe9721e8..f466d28a3cbfe7e83c8914851cfa3897d9cf6dc5 100644 (file)
@@ -1,15 +1,15 @@
 // IMPORT LIBRARIES
 const { DynamicThreadPool } = require('poolifier')
 // FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env['TASK_TYPE']
 }
 
 const dynamicPool = new DynamicThreadPool(
-  Number(size),
+  size,
   size * 3,
   './workers/poolifier/function-to-bench-worker.js'
 )
index a418bcfcf3dbecae289fcaf594da20d06e35a66a..fd0b7bd1caecb76937f27d8195ce2e8e49197f01 100644 (file)
@@ -4,14 +4,14 @@ const { DynamicPool } = require('node-worker-threads-pool')
 // 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 size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env['TASK_TYPE']
 }
 
-const pool = new DynamicPool(Number(size))
+const pool = new DynamicPool(size)
 
 async function run () {
   const promises = []
index 557e45e6eed125969cae9a736eb28f6994371d91..9b9269362c52a55b2718ba3f77c2e42683abafc2 100644 (file)
@@ -1,14 +1,14 @@
 // IMPORT LIBRARIES
 const workerpool = require('workerpool')
 // FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
 const dataArray = ['MYBENCH', process.env['TASK_TYPE']]
 
 const workerPool = workerpool.pool(
   './workers/workerpool/function-to-bench-worker.js',
   {
-    minWorkers: Number(size),
+    minWorkers: size,
     maxWorkers: size * 3,
     workerType: 'thread'
   }
index 4bc64da901eb460001a45889e3af75db63230621..287d8a6f8948a5f164faaf20e784bf1dc6b66bbe 100644 (file)
@@ -4,15 +4,15 @@ const { job, start } = require('microjob')
 // 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 size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env['TASK_TYPE']
 }
 
 async function run () {
-  await start({ maxWorkers: Number(size) })
+  await start({ maxWorkers: size })
   const promises = []
   for (let i = 0; i < iterations; i++) {
     promises.push(
index d01644445a4dff824b3d8df8dfcf119ae2d9f6fb..d1f785edeb31f1ff21870d13b987e8234597a22b 100644 (file)
@@ -1,8 +1,8 @@
 // IMPORT LIBRARIES
 const Piscina = require('piscina')
 // FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env['TASK_TYPE']
@@ -10,7 +10,7 @@ const data = {
 
 const piscina = new Piscina({
   filename: './workers/piscina/function-to-bench-worker.js',
-  minThreads: Number(size),
+  minThreads: size,
   idleTimeout: 1000 * 60 // this is the same as poolifier default
 })
 
index f45734352c698cc49b836232ffc433ae792a3ed6..28aa7e3ab4657baa2410f381af8ce54bd58076bb 100644 (file)
@@ -1,15 +1,15 @@
 // IMPORT LIBRARIES
 const { FixedThreadPool } = require('poolifier')
 // FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env['TASK_TYPE']
 }
 
 const fixedPool = new FixedThreadPool(
-  Number(size),
+  size,
   './workers/poolifier/function-to-bench-worker.js'
 )
 
index dfba6c00f645ccd46b27d8b26513643212a82794..fcc370ff1922f1a06b2f9b05e300872f67bc405e 100644 (file)
@@ -4,8 +4,8 @@ const { ThreadPool } = require('threadwork')
 // 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 size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env['TASK_TYPE']
diff --git a/benchmarks/versus-external-pools/fixed-worker-threads-pool.js b/benchmarks/versus-external-pools/fixed-worker-threads-pool.js
new file mode 100644 (file)
index 0000000..ed7e2ae
--- /dev/null
@@ -0,0 +1,29 @@
+// IMPORT LIBRARIES
+const Pool = require('worker-threads-pool')
+// FINISH IMPORT LIBRARIES
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
+const data = {
+  test: 'MYBENCH',
+  taskType: process.env['TASK_TYPE']
+}
+
+const pool = new Pool({ max: size })
+
+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
+        }
+      )
+    )
+  }
+  await Promise.all(promises)
+  process.exit()
+}
+
+run()
index 5807f67cfd37bf44e008f0d4f0e0034bb4194ac9..cf60a3660eb99bb0e5951e1235702da02853b486 100644 (file)
@@ -1,15 +1,15 @@
 // IMPORT LIBRARIES
 const workerpool = require('workerpool')
 // FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
 const dataArray = ['MYBENCH', process.env['TASK_TYPE']]
 
 const workerPool = workerpool.pool(
   './workers/workerpool/function-to-bench-worker.js',
   {
-    minWorkers: Number(size),
-    maxWorkers: Number(size),
+    minWorkers: size,
+    maxWorkers: size,
     workerType: 'thread'
   }
 )
index 9877bf7518013ef0386016f97e46870b2a3a291b..43eb15f39baacb550d61545da8ed37f5dd551e18 100644 (file)
       }
     },
     "poolifier": {
-      "version": "2.0.0",
-      "resolved": "https://registry.npmjs.org/poolifier/-/poolifier-2.0.0.tgz",
-      "integrity": "sha512-17gRE5OJJvTusOdLzykjrNkFoZFUu2GLKXFrqMqx2EhKmIRS1XzVej+LdhUJn+sdsAap/RQDXVW2u0GcSMSuQQ=="
+      "version": "2.0.1",
+      "resolved": "https://registry.npmjs.org/poolifier/-/poolifier-2.0.1.tgz",
+      "integrity": "sha512-klkLv35QVumXKrQj6Totvwqb0lw34j7mIsEm8uZXXHlcpVCvnhhgVFVyuZUOSNTjZnBCaiB0KcLos03cqj38CA=="
     },
     "symbol-observable": {
       "version": "1.2.0",
index 40d7414985d5e9b755c53de0912099aef203150a..0a0166b804721dddb38f4b3a0fe0f347d13193e7 100644 (file)
@@ -12,7 +12,7 @@
     "microjob": "0.7.0",
     "node-worker-threads-pool": "1.4.3",
     "piscina": "2.2.0",
-    "poolifier": "2.0.0",
+    "poolifier": "2.0.1",
     "threads": "1.6.3",
     "threadwork": "0.6.0",
     "worker-threads-pool": "2.0.0",
index 17543d4bcd45afb4f52cc05f33df223820ad23cb..ded55b882a8e66cd9bfbf0c8367e2b8de6e6eb7a 100644 (file)
@@ -4,15 +4,15 @@ const { StaticPool } = require('node-worker-threads-pool')
 // 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 size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env['TASK_TYPE']
 }
 
 const pool = new StaticPool({
-  size: Number(size),
+  size: size,
   task: functionToBench
 })
 
index df5c087f547d1f2c922d661af0297f7019351392..2cc96d574e6b600a876535723ca3b536373ef4d4 100644 (file)
@@ -1,8 +1,8 @@
 // IMPORT LIBRARIES
 const { spawn, Thread, Worker } = require('threads')
 // FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env['TASK_TYPE']
diff --git a/benchmarks/versus-external-pools/workers/worker-threads-pool/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/worker-threads-pool/function-to-bench-worker.js
new file mode 100644 (file)
index 0000000..202eeb3
--- /dev/null
@@ -0,0 +1,4 @@
+'use strict'
+const { workerData } = require('worker_threads')
+const functionToBench = require('../../functions/function-to-bench')
+functionToBench(workerData)
index 36cd3d91e503ae835900eee606d39b2186209272..aab663c540644925cfb1f43513014ce95472bf0d 100644 (file)
       "requires": {
         "anymatch": "~3.1.1",
         "braces": "~3.0.2",
+        "fsevents": "~2.3.1",
         "glob-parent": "~5.1.0",
         "is-binary-path": "~2.1.0",
         "is-glob": "~4.0.1",