fix: properly size the pools in benchmarking code
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 4 Jul 2023 12:07:43 +0000 (14:07 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 4 Jul 2023 12:07:43 +0000 (14:07 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
.vscode/settings.json
benchmarks/benchmarks-utils.mjs
benchmarks/versus-external-pools/bench.sh
benchmarks/versus-external-pools/dynamic-piscina.mjs
benchmarks/versus-external-pools/dynamic-poolifier.mjs
benchmarks/versus-external-pools/dynamic-tinypool.mjs
benchmarks/versus-external-pools/dynamic-worker-nodes.js
benchmarks/versus-external-pools/dynamic-workerpool.mjs

index 20e48e2dfbfd2f4d3a1650c5d588a01086f94985..867b65ff6268e39989d1e2b1a120dea4c17e204b 100644 (file)
@@ -25,6 +25,7 @@
     "mochawesome",
     "MYBENCH",
     "nocombine",
+    "nproc",
     "octocat",
     "opencollective",
     "OPTARG",
index 56767597b41ff848012c31d9e1f1a92d6415e8e8..48d5e41b1f0138a589fe4dbee31a762ac92db845 100644 (file)
@@ -134,14 +134,14 @@ export const buildPool = (workerType, poolType, poolSize, poolOptions) => {
         case WorkerTypes.thread:
           return new DynamicThreadPool(
             Math.floor(poolSize / 2),
-            poolSize * 3,
+            poolSize,
             './benchmarks/internal/thread-worker.mjs',
             poolOptions
           )
         case WorkerTypes.cluster:
           return new DynamicClusterPool(
             Math.floor(poolSize / 2),
-            poolSize * 3,
+            poolSize,
             './benchmarks/internal/cluster-worker.mjs',
             poolOptions
           )
index e1790aea0be089406ffabe024558ca6c836dedd0..7221ba32e538c089e88636a855a7ea2681b1df76 100755 (executable)
@@ -37,7 +37,7 @@ done
 
 taskType=${taskType:-'CPU_INTENSIVE'}
 taskSize=${taskSize:-5000}
-poolSize=${poolSize:-10}
+poolSize=${poolSize:-$(nproc --all)}
 iterations=${iterations:-100000}
 
 echo 'Running benchmarks with pool size:' ${poolSize}', number of iterations:' ${iterations}', task type:' ${taskType} 'and task size:' ${taskSize}
index 6fcc6793869f38d236c9f956962ed871376fccb6..a1e425f8e95f3a19c8cc5d776cb225fd11f9b200 100644 (file)
@@ -11,8 +11,8 @@ const data = {
 
 const piscina = new Piscina({
   filename: './workers/piscina/function-to-bench-worker.mjs',
-  minThreads: size,
-  maxThreads: size * 3,
+  minThreads: Math.floor(size / 2),
+  maxThreads: size,
   idleTimeout: 60000 // this is the same as poolifier default
 })
 
index 34adba055629ea518de1c0d3de7df2e36311447b..48d3028fb1a1cbd399f608b6d9e956abce3399e0 100644 (file)
@@ -10,8 +10,8 @@ const data = {
 }
 
 const dynamicPool = new DynamicThreadPool(
+  Math.floor(size / 2),
   size,
-  size * 3,
   './workers/poolifier/function-to-bench-worker.mjs'
 )
 
index a28de9b59f7e8e1e03f6de4146a768b4a91c3ff6..acb8627f4f1e2f4ca1592d8aaa29b9f21a6d6160 100644 (file)
@@ -11,8 +11,8 @@ const data = {
 
 const tinypool = new Tinypool({
   filename: './workers/tinypool/function-to-bench-worker.mjs',
-  minThreads: size,
-  maxThreads: size * 3,
+  minThreads: Math.floor(size / 2),
+  maxThreads: size,
   idleTimeout: 60000 // this is the same as poolifier default
 })
 
index 6a55aaf917cfe2d93f4417415bc3c31171113e6f..17255ba2dc2455414a791999233e32e3579a3414 100644 (file)
@@ -13,8 +13,8 @@ const data = {
 const workerNodes = new WorkerNodes(
   require.resolve('./workers/worker-nodes/function-to-bench-worker'),
   {
-    minWorkers: size,
-    maxWorkers: size * 3,
+    minWorkers: Math.floor(size / 2),
+    maxWorkers: size,
     taskTimeout: 60000 // this is the same as poolifier default
   }
 )
index 072aa6fd10fd3d77cf8ee0964bfeb494c16cee66..9dc0e70275ca98f89da39b498bebfb4bce70b273 100644 (file)
@@ -12,8 +12,8 @@ const dataArray = [
 const workerPool = workerpool.pool(
   './workers/workerpool/function-to-bench-worker.mjs',
   {
-    minWorkers: size,
-    maxWorkers: size * 3,
+    minWorkers: Math.floor(size / 2),
+    maxWorkers: size,
     workerType: 'thread'
   }
 )