Initial worker-nodes integration in benchmarks.
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 17 Oct 2022 16:23:50 +0000 (18:23 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 17 Oct 2022 16:23:50 +0000 (18:23 +0200)
Seems to have scalability issue with our workload

Reference #106

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
benchmarks/versus-external-pools/dynamic-worker-nodes.js [new file with mode: 0644]
benchmarks/versus-external-pools/fixed-worker-nodes.js [new file with mode: 0644]
benchmarks/versus-external-pools/functions/function-to-bench.js
benchmarks/versus-external-pools/hyperfine_benchmarks.sh
benchmarks/versus-external-pools/package-lock.json
benchmarks/versus-external-pools/package.json
benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.js [new file with mode: 0644]

diff --git a/benchmarks/versus-external-pools/dynamic-worker-nodes.js b/benchmarks/versus-external-pools/dynamic-worker-nodes.js
new file mode 100644 (file)
index 0000000..6b860d5
--- /dev/null
@@ -0,0 +1,29 @@
+// IMPORT LIBRARIES
+const WorkerNodes = require('worker-nodes')
+// 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 workerNodes = new WorkerNodes(
+  require.resolve('./workers/worker-nodes/function-to-bench-worker'),
+  {
+    minWorkers: size,
+    maxWorkers: size * 3,
+    taskTimeout: 60000 // this is the same as poolifier default
+  }
+)
+
+async function run () {
+  const promises = []
+  for (let i = 0; i < iterations; i++) {
+    promises.push(workerNodes.call.functionToBench(data))
+  }
+  await Promise.all(promises)
+  process.exit()
+}
+
+run()
diff --git a/benchmarks/versus-external-pools/fixed-worker-nodes.js b/benchmarks/versus-external-pools/fixed-worker-nodes.js
new file mode 100644 (file)
index 0000000..58965d2
--- /dev/null
@@ -0,0 +1,29 @@
+// IMPORT LIBRARIES
+const WorkerNodes = require('worker-nodes')
+// 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 workerNodes = new WorkerNodes(
+  require.resolve('./workers/worker-nodes/function-to-bench-worker'),
+  {
+    minWorkers: size,
+    maxWorkers: size,
+    taskTimeout: 60000 // this is the same as poolifier default
+  }
+)
+
+async function run () {
+  const promises = []
+  for (let i = 0; i < iterations; i++) {
+    promises.push(workerNodes.call.functionToBench(data))
+  }
+  await Promise.all(promises)
+  process.exit()
+}
+
+run()
index 565f811219cbccea2cdb1991b1c8a9a337fa9618..b9054db22654b51d16ade84f9adf4c62aca192f4 100644 (file)
@@ -1,14 +1,18 @@
 module.exports = function (data) {
-  if (data.taskType === 'CPU_INTENSIVE') {
-    // CPU intensive task
-    for (let i = 0; i < 5000; i++) {
-      const o = {
-        a: i
+  data = data || {}
+  data.taskType = data.taskType || 'CPU_INTENSIVE'
+  data.taskSize = data.taskSize || 5000
+  switch (data.taskType) {
+    case 'CPU_INTENSIVE':
+      // CPU intensive task
+      for (let i = 0; i < data.taskSize; i++) {
+        const o = {
+          a: i
+        }
+        JSON.stringify(o)
       }
-      JSON.stringify(o)
-    }
-    return { ok: 1 }
-  } else {
-    throw new Error('Please specify the task type')
+      return { ok: 1 }
+    default:
+      throw new Error(`Unknown task type: ${data.taskType}`)
   }
 }
index 1ac1beda0e87f332581410b5dc684a0280f99ee5..b866bb8bfe98067c4b436b07730a5e2c23632cee 100755 (executable)
@@ -1,17 +1,21 @@
 #!/usr/bin/env bash
 
-hyperfine --export-markdown BENCH-100000.md --min-runs 10 \
+hyperfine --export-markdown BENCH-100000.md --min-runs 10 --show-output \
   --prepare 'sleep 15' \
-  'node dynamic-piscina.js' \
-  'node fixed-piscina.js' \
   'node dynamic-poolifier.js' \
   'node fixed-poolifier.js' \
+  'node dynamic-piscina.js' \
+  'node fixed-piscina.js' \
+  'node dynamic-workerpool.js' \
+  'node fixed-workerpool.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-microjob.js' \
+  # Seems to have scalability issues, disabled for now
+  # 'node dynamic-worker-nodes.js' \
+  # 'node fixed-worker-nodes.js'
+
 
 
index 0dce8f65dcd1e4730b47beaa02b67a1d2d8b9c69..77e7497e0b50e42c264015b83279981f5791cb4d 100644 (file)
@@ -14,6 +14,7 @@
         "poolifier": "2.3.3",
         "threads": "1.7.0",
         "threadwork": "0.6.0",
+        "worker-nodes": "2.4.0",
         "workerpool": "6.2.1"
       }
     },
         "esm": "^3.2.25"
       }
     },
+    "node_modules/worker-nodes": {
+      "version": "2.4.0",
+      "resolved": "https://registry.npmjs.org/worker-nodes/-/worker-nodes-2.4.0.tgz",
+      "integrity": "sha512-s32ziQpiWkWbB/ziFKiudpm5/mreSnwpTtKzPxgcPXpl+kXpesiibjM/2Z8i/lDO8kDCUio7wQFXtndopgfsUg==",
+      "engines": {
+        "node": ">=11.7.0"
+      }
+    },
     "node_modules/workerpool": {
       "version": "6.2.1",
       "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz",
         "esm": "^3.2.25"
       }
     },
+    "worker-nodes": {
+      "version": "2.4.0",
+      "resolved": "https://registry.npmjs.org/worker-nodes/-/worker-nodes-2.4.0.tgz",
+      "integrity": "sha512-s32ziQpiWkWbB/ziFKiudpm5/mreSnwpTtKzPxgcPXpl+kXpesiibjM/2Z8i/lDO8kDCUio7wQFXtndopgfsUg=="
+    },
     "workerpool": {
       "version": "6.2.1",
       "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz",
index fe74923a4efeaf79067258a18f068263fe126397..10e566b2dd39d9d83424a2a50fa7a9afa6087685 100644 (file)
@@ -15,6 +15,7 @@
     "poolifier": "2.3.3",
     "threads": "1.7.0",
     "threadwork": "0.6.0",
+    "worker-nodes": "2.4.0",
     "workerpool": "6.2.1"
   }
 }
diff --git a/benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.js
new file mode 100644 (file)
index 0000000..b9a9ea2
--- /dev/null
@@ -0,0 +1,3 @@
+'use strict'
+const functionToBench = require('../../functions/function-to-bench')
+module.exports = { functionToBench }