docs: add tinypool to external pools benchmark
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 19 Jun 2023 12:08:01 +0000 (14:08 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 19 Jun 2023 12:08:01 +0000 (14:08 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
.vscode/settings.json
benchmarks/versus-external-pools/dynamic-tinypool.mjs [new file with mode: 0644]
benchmarks/versus-external-pools/fixed-tinypool.mjs [new file with mode: 0644]
benchmarks/versus-external-pools/hyperfine_benchmarks.sh
benchmarks/versus-external-pools/package.json
benchmarks/versus-external-pools/pnpm-lock.yaml
benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.js [new file with mode: 0644]

index 010c3dc3be8920c42bf28fc4c72367fb08315c95..1004671cb8283803b1f6fe26fcddd69cab2a59a0 100644 (file)
@@ -41,6 +41,7 @@
     "threadjs",
     "THREADPOOL",
     "threadwork",
+    "tinypool",
     "trimmable",
     "tsdoc",
     "typedoc",
diff --git a/benchmarks/versus-external-pools/dynamic-tinypool.mjs b/benchmarks/versus-external-pools/dynamic-tinypool.mjs
new file mode 100644 (file)
index 0000000..18e3866
--- /dev/null
@@ -0,0 +1,32 @@
+// IMPORT LIBRARIES
+import Tinypool from 'tinypool'
+// FINISH IMPORT LIBRARIES
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
+const data = {
+  test: 'MYBENCH',
+  taskType: process.env.TASK_TYPE,
+  taskSize: parseInt(process.env.TASK_SIZE)
+}
+
+const tinypool = new Tinypool({
+  filename: './workers/tinypool/function-to-bench-worker.js',
+  minThreads: size,
+  maxThreads: size * 3,
+  idleTimeout: 60000 // this is the same as poolifier default
+})
+
+/**
+ *
+ */
+async function run () {
+  const promises = []
+  for (let i = 0; i < iterations; i++) {
+    promises.push(tinypool.run(data))
+  }
+  await Promise.all(promises)
+  // eslint-disable-next-line n/no-process-exit
+  process.exit()
+}
+
+run()
diff --git a/benchmarks/versus-external-pools/fixed-tinypool.mjs b/benchmarks/versus-external-pools/fixed-tinypool.mjs
new file mode 100644 (file)
index 0000000..223c0f0
--- /dev/null
@@ -0,0 +1,31 @@
+// IMPORT LIBRARIES
+import Tinypool from 'tinypool'
+// FINISH IMPORT LIBRARIES
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
+const data = {
+  test: 'MYBENCH',
+  taskType: process.env.TASK_TYPE,
+  taskSize: parseInt(process.env.TASK_SIZE)
+}
+
+const tinypool = new Tinypool({
+  filename: './workers/tinypool/function-to-bench-worker.js',
+  minThreads: size,
+  idleTimeout: 60000 // this is the same as poolifier default
+})
+
+/**
+ *
+ */
+async function run () {
+  const promises = []
+  for (let i = 0; i < iterations; i++) {
+    promises.push(tinypool.run(data))
+  }
+  await Promise.all(promises)
+  // eslint-disable-next-line n/no-process-exit
+  process.exit()
+}
+
+run()
index bddeb12e81fead7db576f5646ce968cda5d49c28..9979c573bdc3ec122799daebeaa2a9a696c1d2be 100755 (executable)
@@ -6,6 +6,8 @@ hyperfine --export-markdown BENCH-100000.md --min-runs 10 \
   'node fixed-poolifier.js' \
   'node dynamic-piscina.js' \
   'node fixed-piscina.js' \
+  'node fixed-tinypool.mjs' \
+  'node dynamic-tinypool.mjs' \
   'node dynamic-workerpool.js' \
   'node fixed-workerpool.js' \
   'node dynamic-suchmokuo-node-worker-threads-pool.js' \
index 294332c93a93b084fce773494d27254c1faf705c..d1e5485f2d67a329eeef3c03343f7bfd06b2a0dc 100644 (file)
@@ -23,6 +23,7 @@
     "poolifier": "2.6.2",
     "threads": "1.7.0",
     "threadwork": "0.6.0",
+    "tinypool": "0.5.0",
     "worker-nodes": "2.5.0",
     "workerpool": "6.4.0"
   }
index 62fd7f56827ab8fcb1d0436a42869bafe637856f..08d34f4f59fcf60f76a5c1a642d029baebb9c0eb 100644 (file)
@@ -23,6 +23,9 @@ dependencies:
   threadwork:
     specifier: 0.6.0
     version: 0.6.0
+  tinypool:
+    specifier: 0.5.0
+    version: 0.5.0
   worker-nodes:
     specifier: 2.5.0
     version: 2.5.0
@@ -212,6 +215,11 @@ packages:
     dev: false
     optional: true
 
+  /tinypool@0.5.0:
+    resolution: {integrity: sha512-paHQtnrlS1QZYKF/GnLoOM/DN9fqaGOFbCbxzAhwniySnzl9Ebk8w73/dd34DAhe/obUbPAOldTyYXQZxnPBPQ==}
+    engines: {node: '>=14.0.0'}
+    dev: false
+
   /worker-nodes@2.5.0:
     resolution: {integrity: sha512-0hPZfN21PkMMeljxvFa2+MqOAItvwWnQYMUG6HGhM0X1rTlXPAgVFY+IH4UQC/TmSi/3qMIDdrxArRR8dEdQcQ==}
     engines: {node: '>=11.7.0'}
diff --git a/benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.js
new file mode 100644 (file)
index 0000000..9fa8b47
--- /dev/null
@@ -0,0 +1,3 @@
+'use strict'
+const functionToBench = require('../../functions/function-to-bench')
+module.exports = functionToBench