Add threadwork, microjob to external pools benchmark (#266)
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 12 Mar 2021 19:11:02 +0000 (20:11 +0100)
committerGitHub <noreply@github.com>
Fri, 12 Mar 2021 19:11:02 +0000 (20:11 +0100)
CHANGELOG.md
benchmarks/README.md
benchmarks/versus-external-pools/bench.sh
benchmarks/versus-external-pools/fixed-microjob.js [new file with mode: 0644]
benchmarks/versus-external-pools/fixed-threadwork.js [new file with mode: 0644]

index 211ade56ed3c6528ee1b5c5446bdee50a8ece7f4..e1688efb7497cd0f49f7fd1cfd19cfc2e85c234c 100644 (file)
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
+## [2.0.x] - yyyy-dd-mm
+
+### Bug fixes
+
+- Check if pool options are properly set.
+- `busy` event is emitted on all pool types.
+
 ## [2.0.0] - 2021-01-03
 
 ### Bug fixes
@@ -13,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Breaking Changes
 
-- `FullPool` event is now renamed to `busy` and emitted on all pool types.
+- `FullPool` event is now renamed to `busy`.
 - `maxInactiveTime` on `ThreadWorker` default behavior is now changed, if you want to keep the old behavior set `killBehavior` to `KillBehaviors.HARD`.
   _Find more details on our JSDoc._
 
index 61b57518fecd5346ae814c8b90dd25bb82e89eef..bdec9bf225305dea2cad104cbdf29f2cb31ff7cd 100644 (file)
@@ -16,6 +16,9 @@ External pools with which we compared the poolifier results:
 - [piscina](https://github.com/piscinajs/piscina)
 - [SUCHMOKUO/node-worker-threads-pool](https://github.com/SUCHMOKUO/node-worker-threads-pool)
 - [threads.js](https://github.com/andywer/threads.js/)
+- [workerpool](https://github.com/josdejong/workerpool)
+- [threadwork](https://github.com/kevlened/threadwork)
+- [microjob](https://github.com/wilk/microjob)
 
 Those are our results:
 
index ae5b76ee0f4d6c04cad51b2dedc6318b7c63a1ea..d3f512165ad73561f5211d4e1245c403e9b2d6d6 100755 (executable)
@@ -25,4 +25,6 @@ hyperfine --export-markdown BENCH-100000.md --min-runs 10 \
   'node static-suchmokuo-node-worker-threads-pool.js' \
   'node threadjs.js' \
   'node dynamic-workerpool.js' \
-  'node fixed-workerpool.js'
+  'node fixed-workerpool.js' \
+  'node fixed-threadwork.js' \
+  'node fixed-microjob.js'
diff --git a/benchmarks/versus-external-pools/fixed-microjob.js b/benchmarks/versus-external-pools/fixed-microjob.js
new file mode 100644 (file)
index 0000000..4bc64da
--- /dev/null
@@ -0,0 +1,31 @@
+// IMPORT LIBRARIES
+const { job, start } = require('microjob')
+// FINISH IMPORT LIBRARIES
+// IMPORT FUNCTION TO BENCH
+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',
+  taskType: process.env['TASK_TYPE']
+}
+
+async function run () {
+  await start({ maxWorkers: Number(size) })
+  const promises = []
+  for (let i = 0; i < iterations; i++) {
+    promises.push(
+      job(
+        data => {
+          functionToBench(data)
+        },
+        { data: data, ctx: { functionToBench } }
+      )
+    )
+  }
+  await Promise.all(promises)
+  process.exit()
+}
+
+run()
diff --git a/benchmarks/versus-external-pools/fixed-threadwork.js b/benchmarks/versus-external-pools/fixed-threadwork.js
new file mode 100644 (file)
index 0000000..dfba6c0
--- /dev/null
@@ -0,0 +1,25 @@
+// IMPORT LIBRARIES
+const { ThreadPool } = require('threadwork')
+// FINISH IMPORT LIBRARIES
+// IMPORT FUNCTION TO BENCH
+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',
+  taskType: process.env['TASK_TYPE']
+}
+
+const threadPool = new ThreadPool({ task: functionToBench, size: size })
+
+async function run () {
+  const promises = []
+  for (let i = 0; i < iterations; i++) {
+    promises.push(threadPool.run(data))
+  }
+  await Promise.all(promises)
+  process.exit()
+}
+
+run()