Add workerpool to external pools benchmark (#263)
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 9 Mar 2021 09:36:41 +0000 (10:36 +0100)
committerGitHub <noreply@github.com>
Tue, 9 Mar 2021 09:36:41 +0000 (10:36 +0100)
benchmarks/versus-external-pools/bench.sh
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 [new file with mode: 0644]
benchmarks/versus-external-pools/fixed-poolifier.js
benchmarks/versus-external-pools/fixed-workerpool.js [new file with mode: 0644]
benchmarks/versus-external-pools/functions/function-to-bench.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/workers/workerpool/function-to-bench-worker.js [new file with mode: 0644]

index b6c339f84a1f3b408aaa4b30349b3f745cf26acf..ae5b76ee0f4d6c04cad51b2dedc6318b7c63a1ea 100755 (executable)
@@ -21,6 +21,8 @@ hyperfine --export-markdown BENCH-100000.md --min-runs 10 \
   'node fixed-piscina.js' \
   'node dynamic-poolifier.js' \
   'node fixed-poolifier.js' \
-  'node static-suchmokuo-node-worker-threads-pool.js' \
   'node dynamic-suchmokuo-node-worker-threads-pool.js' \
-  'node threadjs.js'
+  'node static-suchmokuo-node-worker-threads-pool.js' \
+  'node threadjs.js' \
+  'node dynamic-workerpool.js' \
+  'node fixed-workerpool.js'
index 3c51ac4cde7ce323f739849e17b4757bece8dbb4..b20082a3541dfc9237c311a6c07c831fbe9721e8 100644 (file)
@@ -1,5 +1,5 @@
 // IMPORT LIBRARIES
-const { FixedThreadPool, DynamicThreadPool } = require('poolifier')
+const { DynamicThreadPool } = require('poolifier')
 // FINISH IMPORT LIBRARIES
 const size = process.env.POOL_SIZE
 const iterations = process.env.NUM_ITERATIONS
index c183e536c688235b734943e000614df13ddcd748..a418bcfcf3dbecae289fcaf594da20d06e35a66a 100644 (file)
@@ -1,5 +1,5 @@
 // IMPORT LIBRARIES
-const { DynamicPool, StaticPool } = require('node-worker-threads-pool')
+const { DynamicPool } = require('node-worker-threads-pool')
 // FINISH IMPORT LIBRARIES
 // IMPORT FUNCTION TO BENCH
 const functionToBench = require('./functions/function-to-bench')
diff --git a/benchmarks/versus-external-pools/dynamic-workerpool.js b/benchmarks/versus-external-pools/dynamic-workerpool.js
new file mode 100644 (file)
index 0000000..557e45e
--- /dev/null
@@ -0,0 +1,26 @@
+// IMPORT LIBRARIES
+const workerpool = require('workerpool')
+// FINISH IMPORT LIBRARIES
+const size = process.env.POOL_SIZE
+const iterations = 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: size * 3,
+    workerType: 'thread'
+  }
+)
+
+async function run () {
+  const promises = []
+  for (let i = 0; i < iterations; i++) {
+    promises.push(workerPool.exec('functionToBench', dataArray))
+  }
+  await Promise.all(promises)
+  process.exit()
+}
+
+run()
index e32a1166f63847a45933209fa3bd71d3a1c43e00..f45734352c698cc49b836232ffc433ae792a3ed6 100644 (file)
@@ -1,5 +1,5 @@
 // IMPORT LIBRARIES
-const { FixedThreadPool, DynamicThreadPool } = require('poolifier')
+const { FixedThreadPool } = require('poolifier')
 // FINISH IMPORT LIBRARIES
 const size = process.env.POOL_SIZE
 const iterations = process.env.NUM_ITERATIONS
diff --git a/benchmarks/versus-external-pools/fixed-workerpool.js b/benchmarks/versus-external-pools/fixed-workerpool.js
new file mode 100644 (file)
index 0000000..5807f67
--- /dev/null
@@ -0,0 +1,26 @@
+// IMPORT LIBRARIES
+const workerpool = require('workerpool')
+// FINISH IMPORT LIBRARIES
+const size = process.env.POOL_SIZE
+const iterations = 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),
+    workerType: 'thread'
+  }
+)
+
+async function run () {
+  const promises = []
+  for (let i = 0; i < iterations; i++) {
+    promises.push(workerPool.exec('functionToBench', dataArray))
+  }
+  await Promise.all(promises)
+  process.exit()
+}
+
+run()
index 23312bfcac0b26794f20c253411f066baedbe854..48a0fc78c8851f6c31c3e87d7d7d35eb3b6e0dc2 100644 (file)
@@ -1,6 +1,6 @@
 module.exports = function (data) {
   if (data.taskType === 'CPU_INTENSIVE') {
-    // CPU Intensive task
+    // CPU intensive task
     for (let i = 0; i <= 5000; i++) {
       const o = {
         a: i
index e05eac1ce9d5cd0d8922346b0b8d6de66fd60b5f..9877bf7518013ef0386016f97e46870b2a3a291b 100644 (file)
       }
     },
     "workerpool": {
-      "version": "6.1.0",
-      "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.1.0.tgz",
-      "integrity": "sha512-toV7q9rWNYha963Pl/qyeZ6wG+3nnsyvolaNUS8+R5Wtw6qJPTxIlOP1ZSvcGhEJw+l3HMMmtiNo9Gl61G4GVg=="
+      "version": "6.1.2",
+      "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.1.2.tgz",
+      "integrity": "sha512-I/gDW4LwV3bslk4Yiqd4XoNYlnvV03LON7KuIjmQ90yDnKND1sR2LK/JA1g1tmd71oe6KPSvN0JpBzXIH6xAgA=="
     },
     "wrappy": {
       "version": "1.0.2",
index 1f5d1735d6d1f7898c94cce9f9ec7ce0a269c0b4..40d7414985d5e9b755c53de0912099aef203150a 100644 (file)
@@ -16,6 +16,6 @@
     "threads": "1.6.3",
     "threadwork": "0.6.0",
     "worker-threads-pool": "2.0.0",
-    "workerpool": "6.1.0"
+    "workerpool": "6.1.2"
   }
 }
index fa151d586947c719db67f6697314d0b2779284dd..17543d4bcd45afb4f52cc05f33df223820ad23cb 100644 (file)
@@ -1,5 +1,5 @@
 // IMPORT LIBRARIES
-const { DynamicPool, StaticPool } = require('node-worker-threads-pool')
+const { StaticPool } = require('node-worker-threads-pool')
 // FINISH IMPORT LIBRARIES
 // IMPORT FUNCTION TO BENCH
 const functionToBench = require('./functions/function-to-bench')
diff --git a/benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.js
new file mode 100644 (file)
index 0000000..02f777f
--- /dev/null
@@ -0,0 +1,11 @@
+'use strict'
+const workerpool = require('workerpool')
+const functionToBench = require('../../functions/function-to-bench')
+
+function workerPoolWrapperFunctionToBench (testName, taskType) {
+  return functionToBench({ test: testName, taskType: taskType })
+}
+
+workerpool.worker({
+  functionToBench: workerPoolWrapperFunctionToBench
+})