Improvement on benchmarks
authoraardizio <alessandroardizio94@gmail.com>
Mon, 22 Feb 2021 15:13:01 +0000 (16:13 +0100)
committeraardizio <alessandroardizio94@gmail.com>
Mon, 22 Feb 2021 15:13:01 +0000 (16:13 +0100)
16 files changed:
benchmarks/README.md
benchmarks/versus-external-pools/BENCH-100000.MD
benchmarks/versus-external-pools/bench.sh
benchmarks/versus-external-pools/dynamic-piscina.js [moved from benchmarks/versus-external-pools/piscina.js with 81% similarity]
benchmarks/versus-external-pools/dynamic-poolifier.js
benchmarks/versus-external-pools/dynamic-suchmokuo-node-worker-threads-pool.js
benchmarks/versus-external-pools/fixed-piscina.js [new file with mode: 0644]
benchmarks/versus-external-pools/fixed-poolifier.js
benchmarks/versus-external-pools/functions/function-to-bench.js [new file with mode: 0644]
benchmarks/versus-external-pools/functions/json-stringify.js [deleted file]
benchmarks/versus-external-pools/package-lock.json
benchmarks/versus-external-pools/static-suchmokuo-node-worker-threads-pool.js
benchmarks/versus-external-pools/workers/piscina/function-to-bench-worker.js [new file with mode: 0644]
benchmarks/versus-external-pools/workers/piscina/json-stringify.worker.js [deleted file]
benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.js [new file with mode: 0644]
benchmarks/versus-external-pools/workers/poolifier/json-stringify.worker.js [deleted file]

index 907d8649075444943d775798920034e00eecc95e..30bb4515d2ab04410ef75a7a414803bdb401046a 100644 (file)
@@ -12,11 +12,10 @@ The versus-external-pools folder contains benchmarks versus other Node.js pools.
 To compare poolifier pools performance vs other pools performance we chose to use [hyperfine](https://github.com/sharkdp/hyperfine).
 We chose to use this tool because it allows to run isolated Node.js processes so that each pool does not impact each other.
 
-We will add more details on each function that we benchmark.
-
 Those are our results:
 
-- CPU Intensive task with 100k operations submitted to each pool [BENCH-100000.MD](./versus-external-pools/BENCH-100000.MD)
+- CPU Intensive task with 100k operations submitted to each pool [BENCH-100000.MD](./versus-external-pools/BENCH-100000.MD).  
+This benchmark ran on a MacBook Pro 2015, 2,2 GHz Intel Core i7 quad-core, 16 GB 1600 MHz DDR3
 
 ## How to run benchmarks
 
@@ -30,3 +29,5 @@ To run the benchmark versus other pools you will need to:
 
 - [Install hyperfine](https://github.com/sharkdp/hyperfine#installation)
 - Run the `./bench.sh` into the `versus-external-pools` folder
+
+> :warning: **Please be sure to use a quite PC when you run the benchmarks**
index cd14d108d3d738fc01b7a3ae46b81eff2db30eee..27371b2b4f4259e215b4cd5025e6a46036a99b42 100644 (file)
@@ -1,5 +1,8 @@
 | Command | Mean [s] | Min [s] | Max [s] | Relative |
 |:---|---:|---:|---:|---:|
-| `node static-suchmokuo-node-worker-threads-pool.js` | 47.473 ± 1.241 | 44.031 | 48.331 | 1.05 ± 0.03 |
-| `node dynamic-poolifier.js` | 45.368 ± 0.173 | 45.028 | 45.595 | 1.00 |
-| `node piscina.js` | 48.502 ± 0.390 | 47.896 | 49.362 | 1.07 ± 0.01 |
+| `node static-suchmokuo-node-worker-threads-pool.js` | 50.403 ± 1.280 | 46.822 | 51.241 | 1.04 ± 0.04 |
+| `node dynamic-suchmokuo-node-worker-threads-pool.js` | 62.664 ± 0.158 | 62.329 | 62.852 | 1.29 ± 0.03 |
+| `node dynamic-poolifier.js` | 48.517 ± 1.233 | 47.662 | 51.249 | 1.00 |
+| `node fixed-poolifier.js` | 48.539 ± 1.247 | 47.848 | 52.056 | 1.00 ± 0.04 |
+| `node dynamic-piscina.js` | 51.187 ± 0.184 | 50.986 | 51.579 | 1.06 ± 0.03 |
+| `node fixed-piscina.js` | 51.259 ± 0.087 | 51.114 | 51.404 | 1.06 ± 0.03 |
index 05c156c92b27d774f56e742b19e1df7fe81e916e..290df239c141e89a7154fd972d7a6c7326b162cb 100755 (executable)
@@ -1,37 +1,24 @@
-export NODE_ENV=production
-
-# Execute bench
-# export POOL_SIZE=8
-# export NUM_ITERATIONS=10000
-# hyperfine --export-markdown BENCH-10000.MD --min-runs 10 \
-#   'node dynamic-poolifier.js' \
-#   'node dynamic-suchmokuo-node-worker-threads-pool.js' \
-#   'node fixed-poolifier.js' \
-#   'node static-suchmokuo-node-worker-threads-pool.js' \
-#   'node piscina.js'
+### The -t argument is needed to specify the type of task that you want to benchmark.
+### Supported values are CPU_INTENSIVE
 
-# echo "Sleeping...."
-# sleep 60
+taskType='CPU_INTENSIVE'
+while getopts t: flag
+do
+    case "${flag}" in
+        t) taskType=${OPTARG};;
+    esac
+done
 
+echo 'Running bench for task type:' $taskType
+export TASK_TYPE=$taskType
+# Execute bench
+export NODE_ENV=production
 export POOL_SIZE=10
 export NUM_ITERATIONS=100000
 hyperfine --export-markdown BENCH-100000.MD --min-runs 10 \
   'node static-suchmokuo-node-worker-threads-pool.js' \
+  'node dynamic-suchmokuo-node-worker-threads-pool.js' \
   'node dynamic-poolifier.js' \
-  'node piscina.js'
-
-# export POOL_SIZE=8
-# export NUM_ITERATIONS=50000
-# hyperfine --export-markdown BENCH-50000.MD --min-runs 10 \
-#   'node dynamic-poolifier.js' \
-#   'node dynamic-suchmokuo-node-worker-threads-pool.js' \
-#   'node fixed-poolifier.js' \
-#   'node static-suchmokuo-node-worker-threads-pool.js' \
-#   'node piscina.js'
-
-# export NUM_ITERATIONS=100000
-#   hyperfine --export-markdown BENCH-50000.MD --min-runs 20 \
-#     'node dynamic-poolifier.js' \
-#     'node static-suchmokuo-node-worker-threads-pool.js' \
-#     'node piscina.js'
-
+  'node fixed-poolifier.js' \
+  'node dynamic-piscina.js' \
+  'node fixed-piscina.js'
similarity index 81%
rename from benchmarks/versus-external-pools/piscina.js
rename to benchmarks/versus-external-pools/dynamic-piscina.js
index 297ea681df1d6c2dec818febebdf416b10a18a5b..0881d1d051c9f69914c8ff300e69c30e843166a2 100644 (file)
@@ -4,11 +4,12 @@ const Piscina = require('piscina')
 const size = process.env.POOL_SIZE
 const iterations = process.env.NUM_ITERATIONS
 const data = {
-  test: 'MYBENCH'
+  test: 'MYBENCH',
+  taskType: process.env['TASK_TYPE']
 }
 
 const piscina = new Piscina({
-  filename: './workers/piscina/json-stringify.worker.js',
+  filename: './workers/piscina/function-to-bench-worker.js',
   minThreads: Number(size),
   maxThreads: size * 3,
   idleTimeout: 1000 * 60 // this is the same as poolifier default
index e4f5f1322c45812f8750c1e43fa6de3ad3685256..6a7406bc9913c0a83efd918008dd27418efed3e1 100644 (file)
@@ -4,13 +4,14 @@ const { FixedThreadPool, DynamicThreadPool } = require('poolifier')
 const size = process.env.POOL_SIZE
 const iterations = process.env.NUM_ITERATIONS
 const data = {
-  test: 'MYBENCH'
+  test: 'MYBENCH',
+  taskType: process.env['TASK_TYPE']
 }
 
 const dynamicPool = new DynamicThreadPool(
   size,
   size * 3,
-  './workers/poolifier/json-stringify.worker.js',
+  './workers/poolifier/function-to-bench-worker.js',
   {
     maxTasks: 10000
   }
index 8bf964d24119aa5cbaf746378859a2c8065add74..c183e536c688235b734943e000614df13ddcd748 100644 (file)
@@ -2,12 +2,13 @@
 const { DynamicPool, StaticPool } = require('node-worker-threads-pool')
 // FINISH IMPORT LIBRARIES
 // IMPORT FUNCTION TO BENCH
-const functionToBench = require('./functions/json-stringify')
+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 data = {
-  test: 'MYBENCH'
+  test: 'MYBENCH',
+  taskType: process.env['TASK_TYPE']
 }
 
 const pool = new DynamicPool(Number(size))
diff --git a/benchmarks/versus-external-pools/fixed-piscina.js b/benchmarks/versus-external-pools/fixed-piscina.js
new file mode 100644 (file)
index 0000000..d016444
--- /dev/null
@@ -0,0 +1,26 @@
+// IMPORT LIBRARIES
+const Piscina = require('piscina')
+// FINISH IMPORT LIBRARIES
+const size = process.env.POOL_SIZE
+const iterations = process.env.NUM_ITERATIONS
+const data = {
+  test: 'MYBENCH',
+  taskType: process.env['TASK_TYPE']
+}
+
+const piscina = new Piscina({
+  filename: './workers/piscina/function-to-bench-worker.js',
+  minThreads: Number(size),
+  idleTimeout: 1000 * 60 // this is the same as poolifier default
+})
+
+async function run () {
+  const promises = []
+  for (let i = 0; i < iterations; i++) {
+    promises.push(piscina.runTask(data))
+  }
+  await Promise.all(promises)
+  process.exit()
+}
+
+run()
index b62cd5934424a0fb9dc3422011ba98242ae717be..c994620899f15283d478b3d9494186607b109a66 100644 (file)
@@ -4,12 +4,13 @@ const { FixedThreadPool, DynamicThreadPool } = require('poolifier')
 const size = process.env.POOL_SIZE
 const iterations = process.env.NUM_ITERATIONS
 const data = {
-  test: 'MYBENCH'
+  test: 'MYBENCH',
+  taskType: process.env['TASK_TYPE']
 }
 
 const fixedPool = new FixedThreadPool(
   size,
-  './workers/poolifier/json-stringify.worker.js',
+  './workers/poolifier/function-to-bench-worker.js',
   {
     maxTasks: 100000
   }
diff --git a/benchmarks/versus-external-pools/functions/function-to-bench.js b/benchmarks/versus-external-pools/functions/function-to-bench.js
new file mode 100644 (file)
index 0000000..0c9738e
--- /dev/null
@@ -0,0 +1,14 @@
+module.exports = function (data) {
+  if ( data.taskType === 'CPU_INTENSIVE' ) {
+    // CPU Intensive task
+    for (let i = 0; i <= 5000; i++) {
+      const o = {
+        a: i
+      }
+      JSON.stringify(o)
+    }
+    return { ok: 1 }
+  } else {
+    throw new Error('Please specify the task type')
+  }
+}
diff --git a/benchmarks/versus-external-pools/functions/json-stringify.js b/benchmarks/versus-external-pools/functions/json-stringify.js
deleted file mode 100644 (file)
index 4b00910..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-module.exports = function (data) {
-  for (let i = 0; i <= 5000; i++) {
-    const o = {
-      a: i
-    }
-    JSON.stringify(o)
-  }
-  // console.log('STRINGIFY FUNCTION FINISHED')
-  return { ok: 1 }
-}
index 11c2250f7704487de747bfb0b1d23aea5d1f7769..d7e702d5771dc939b1461de88a493ed83f096382 100644 (file)
       "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg=="
     },
     "poolifier": {
-      "version": "2.0.0-beta.6",
-      "resolved": "https://registry.npmjs.org/poolifier/-/poolifier-2.0.0-beta.6.tgz",
-      "integrity": "sha512-n+IumaVITBY1/UD4gC4e6uXHlBIgy2+AKeX4BmhEP4phIM6DCYBYBRuVk5lk8LlXKiO8HFrQ3WXHzCpubqWyqA=="
+      "version": "2.0.0-beta.7",
+      "resolved": "https://registry.npmjs.org/poolifier/-/poolifier-2.0.0-beta.7.tgz",
+      "integrity": "sha512-ZGrwPJdCRlQu3oIIAZBZQgrjOPzLUU+GNpPP4KpvVplL+XeDYHzIqtiss9M/3rYgmFuus6DiUd5JFWqnb5dtLg=="
     },
     "symbol-observable": {
       "version": "1.2.0",
index df7edd81519e0500305b0de60885ab43bc13dd8d..fa151d586947c719db67f6697314d0b2779284dd 100644 (file)
@@ -2,12 +2,13 @@
 const { DynamicPool, StaticPool } = require('node-worker-threads-pool')
 // FINISH IMPORT LIBRARIES
 // IMPORT FUNCTION TO BENCH
-const functionToBench = require('./functions/json-stringify')
+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 data = {
-  test: 'MYBENCH'
+  test: 'MYBENCH',
+  taskType: process.env['TASK_TYPE']
 }
 
 const pool = new StaticPool({
diff --git a/benchmarks/versus-external-pools/workers/piscina/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/piscina/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
diff --git a/benchmarks/versus-external-pools/workers/piscina/json-stringify.worker.js b/benchmarks/versus-external-pools/workers/piscina/json-stringify.worker.js
deleted file mode 100644 (file)
index 154e04a..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-'use strict'
-const jsonStringify = require('../../functions/json-stringify')
-module.exports = jsonStringify
diff --git a/benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.js b/benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.js
new file mode 100644 (file)
index 0000000..99af6ea
--- /dev/null
@@ -0,0 +1,4 @@
+'use strict'
+const { ThreadWorker } = require('poolifier')
+const functionToBench = require('../../functions/function-to-bench')
+module.exports = new ThreadWorker(functionToBench)
diff --git a/benchmarks/versus-external-pools/workers/poolifier/json-stringify.worker.js b/benchmarks/versus-external-pools/workers/poolifier/json-stringify.worker.js
deleted file mode 100644 (file)
index 73d0885..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-'use strict'
-const { ThreadWorker } = require('poolifier')
-const jsonStringify = require('../../functions/json-stringify')
-module.exports = new ThreadWorker(jsonStringify)