refactor: partially revert ESM conversion in benchmarking code
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 26 Jun 2023 11:07:17 +0000 (13:07 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 26 Jun 2023 11:07:17 +0000 (13:07 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
16 files changed:
benchmarks/README.md
benchmarks/versus-external-pools/dynamic-node-worker-threads-pool.mjs
benchmarks/versus-external-pools/dynamic-worker-nodes.js [moved from benchmarks/versus-external-pools/dynamic-worker-nodes.mjs with 71% similarity]
benchmarks/versus-external-pools/fixed-microjob.mjs
benchmarks/versus-external-pools/fixed-worker-nodes.js [moved from benchmarks/versus-external-pools/fixed-worker-nodes.mjs with 71% similarity]
benchmarks/versus-external-pools/functions/function-to-bench.js [moved from benchmarks/versus-external-pools/functions/function-to-bench.mjs with 92% similarity]
benchmarks/versus-external-pools/hyperfine_benchmarks.sh
benchmarks/versus-external-pools/pool-threadwork.mjs
benchmarks/versus-external-pools/static-node-worker-threads-pool.mjs
benchmarks/versus-external-pools/workers/piscina/function-to-bench-worker.mjs
benchmarks/versus-external-pools/workers/poolifier/function-to-bench-worker.mjs
benchmarks/versus-external-pools/workers/threadjs/function-to-bench-worker.mjs
benchmarks/versus-external-pools/workers/tinypool/function-to-bench-worker.mjs
benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.js [new file with mode: 0644]
benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.mjs [deleted file]
benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.mjs

index fcbfd6525acdfdb5f23a4d86eabc22b576ee9832..3b7f0702557e379169ee8b16586bec6ba6ebefa5 100644 (file)
@@ -17,6 +17,7 @@ External pools with which we compared the poolifier results:
 - [tinypool](https://github.com/tinylibs/tinypool)
 - [workerpool](https://github.com/josdejong/workerpool)
 - [worker-nodes](https://github.com/allegro/node-worker-nodes)
+- [node-worker-threads-pool](https://github.com/SUCHMOKUO/node-worker-threads-pool)
 - [threads.js](https://github.com/andywer/threads.js/)
 - [threadwork](https://github.com/kevlened/threadwork)
 - [microjob](https://github.com/wilk/microjob)
@@ -29,7 +30,8 @@ Those are our results:
 
 External pools with which we used to compare the poolifier results:
 
-- [node-worker-threads-pool](https://github.com/SUCHMOKUO/node-worker-threads-pool): removed because it does not support dynamic modules import or import outside the worker function. The worker function is expected to be self-contained, which makes it difficult to use in real world application without ugly hacks.
+<!-- - [node-worker-threads-pool](https://github.com/SUCHMOKUO/node-worker-threads-pool): removed because it does not support dynamic modules import or import outside the worker function. The worker function is expected to be self-contained, which makes it difficult to use in real world application without ugly hacks. -->
+
 - [worker-threads-pool](https://github.com/watson/worker-threads-pool): removed because unmaintained since more than 4 years.
 
 ### Internal
index 743b01d64e2b6086af087311809825d56c533f6d..debe85132cf190fb262f2bac3d4f4032772540bb 100644 (file)
@@ -2,7 +2,7 @@
 import { DynamicPool } from 'node-worker-threads-pool'
 // FINISH IMPORT LIBRARIES
 // IMPORT FUNCTION TO BENCH
-import functionToBench from './functions/function-to-bench.mjs'
+import functionToBench from './functions/function-to-bench.js'
 // FINISH IMPORT FUNCTION TO BENCH
 const size = parseInt(process.env.POOL_SIZE)
 const iterations = parseInt(process.env.NUM_ITERATIONS)
similarity index 71%
rename from benchmarks/versus-external-pools/dynamic-worker-nodes.mjs
rename to benchmarks/versus-external-pools/dynamic-worker-nodes.js
index 5404c9b8235be0c14df4deb76beccf52a4be61ab..fffa55948228696811dd1961f306df2241c44ae2 100644 (file)
@@ -1,5 +1,5 @@
 // IMPORT LIBRARIES
-import WorkerNodes from 'worker-nodes'
+const WorkerNodes = require('worker-nodes')
 // FINISH IMPORT LIBRARIES
 const size = parseInt(process.env.POOL_SIZE)
 const iterations = parseInt(process.env.NUM_ITERATIONS)
@@ -10,7 +10,7 @@ const data = {
 }
 
 const workerNodes = new WorkerNodes(
-  import.meta.resolve('./workers/worker-nodes/function-to-bench-worker'),
+  require.resolve('./workers/worker-nodes/function-to-bench-worker'),
   {
     minWorkers: size,
     maxWorkers: size * 3,
@@ -28,4 +28,12 @@ async function run () {
   process.exit()
 }
 
-await run()
+(async () => {
+  try {
+    await run()
+  } catch (e) {
+    console.error(e)
+    // eslint-disable-next-line n/no-process-exit
+    process.exit(1)
+  }
+})()
index f4e121a549bdfdb1aca2f935eac690f503ad1171..850758656f5c9725e7118260eed223c3d52378a3 100644 (file)
@@ -2,7 +2,7 @@
 import { job, start } from 'microjob'
 // FINISH IMPORT LIBRARIES
 // IMPORT FUNCTION TO BENCH
-import functionToBench from './functions/function-to-bench.mjs'
+import functionToBench from './functions/function-to-bench.js'
 // FINISH IMPORT FUNCTION TO BENCH
 const size = parseInt(process.env.POOL_SIZE)
 const iterations = parseInt(process.env.NUM_ITERATIONS)
similarity index 71%
rename from benchmarks/versus-external-pools/fixed-worker-nodes.mjs
rename to benchmarks/versus-external-pools/fixed-worker-nodes.js
index bffef10c1c171ff66c86857980845bced4016ef6..641afd77ecf430efbedd2fd089452496c75f008e 100644 (file)
@@ -1,5 +1,5 @@
 // IMPORT LIBRARIES
-import WorkerNodes from 'worker-nodes'
+const WorkerNodes = require('worker-nodes')
 // FINISH IMPORT LIBRARIES
 const size = parseInt(process.env.POOL_SIZE)
 const iterations = parseInt(process.env.NUM_ITERATIONS)
@@ -10,7 +10,7 @@ const data = {
 }
 
 const workerNodes = new WorkerNodes(
-  import.meta.resolve('./workers/worker-nodes/function-to-bench-worker'),
+  require.resolve('./workers/worker-nodes/function-to-bench-worker'),
   {
     minWorkers: size,
     maxWorkers: size,
@@ -28,4 +28,12 @@ async function run () {
   process.exit()
 }
 
-await run()
+(async () => {
+  try {
+    await run()
+  } catch (e) {
+    console.error(e)
+    // eslint-disable-next-line n/no-process-exit
+    process.exit(1)
+  }
+})()
similarity index 92%
rename from benchmarks/versus-external-pools/functions/function-to-bench.mjs
rename to benchmarks/versus-external-pools/functions/function-to-bench.js
index 4705273c07e1bd1437d84f75d2a74782747d8e11..74a07d1ef1ac4f410e8fada4679f1ed64d3bcac1 100644 (file)
@@ -1,13 +1,12 @@
-import crypto from 'crypto'
-import fs from 'fs'
-
 /**
  * The worker function to execute during pools benchmarks.
  * NOTE: This function requires to be self-contained, thread-safe and re-entrant.
  * @param {*} data The worker data.
  * @returns {*} The result.
  */
-export default function functionToBench (data) {
+module.exports = function functionToBench (data) {
+  const crypto = require('crypto')
+  const fs = require('fs')
   const TaskTypes = {
     CPU_INTENSIVE: 'CPU_INTENSIVE',
     IO_INTENSIVE: 'IO_INTENSIVE'
index b73ccaf404cff1ec6826706528e8ca7ac67650e8..b6534d825e6bc9a1f2f3d66e3675776c3e61a3ef 100755 (executable)
@@ -9,8 +9,10 @@ hyperfine --export-markdown BENCH-100000.md --min-runs 20 --prepare 'sleep 2' --
   'node dynamic-tinypool.mjs' \
   'node dynamic-workerpool.mjs' \
   'node fixed-workerpool.mjs' \
-  'node --experimental-import-meta-resolve dynamic-worker-nodes.mjs' \
-  'node --experimental-import-meta-resolve fixed-worker-nodes.mjs' \
+  'node dynamic-worker-nodes.js' \
+  'node fixed-worker-nodes.js' \
+  'node dynamic-node-worker-threads-pool.mjs' \
+  'node static-node-worker-threads-pool.mjs' \
   'node threadjs.mjs' \
   'node fixed-threadwork.mjs' \
   'node fixed-microjob.mjs'
index 4541e58c97a8833f07185ab9d735e269787685f3..545c013eddbbd3e8d016b13080f7e1610fba2999 100644 (file)
@@ -2,7 +2,7 @@
 import { ThreadPool } from 'threadwork'
 // FINISH IMPORT LIBRARIES
 // IMPORT FUNCTION TO BENCH
-import functionToBench from './functions/function-to-bench.mjs'
+import functionToBench from './functions/function-to-bench.js'
 // FINISH IMPORT FUNCTION TO BENCH
 const size = parseInt(process.env.POOL_SIZE)
 
index b943be5d4a60e1531371ce5151af359cde815674..b8a90ea321ccae3cf912b010ce8d4d21b30a7a53 100644 (file)
@@ -2,7 +2,7 @@
 import { StaticPool } from 'node-worker-threads-pool'
 // FINISH IMPORT LIBRARIES
 // IMPORT FUNCTION TO BENCH
-import functionToBench from './functions/function-to-bench.mjs'
+import functionToBench from './functions/function-to-bench.js'
 // FINISH IMPORT FUNCTION TO BENCH
 const size = parseInt(process.env.POOL_SIZE)
 const iterations = parseInt(process.env.NUM_ITERATIONS)
index 3a33592841d81567f73f6975052f6ba885e800e6..41f6fd797156b94fc890c530efb9c8e7109480bd 100644 (file)
@@ -1,2 +1,2 @@
-import functionToBench from '../../functions/function-to-bench.mjs'
+import functionToBench from '../../functions/function-to-bench.js'
 export default functionToBench
index f889e44a0622d5bdc55be80773c8a516cdbbe0ad..3b058629de9f792e497662c408605f545d49260a 100644 (file)
@@ -1,3 +1,3 @@
 import { ThreadWorker } from 'poolifier'
-import functionToBench from '../../functions/function-to-bench.mjs'
+import functionToBench from '../../functions/function-to-bench.js'
 export default new ThreadWorker(functionToBench)
index d77174f92fac864bb706c70083ea7bc05eaf8db4..8217e22d9e7f79167c95acfd8dd0c56385fcad2b 100644 (file)
@@ -1,5 +1,5 @@
 import { expose } from 'threads/worker'
-import functionToBench from '../../functions/function-to-bench.mjs'
+import functionToBench from '../../functions/function-to-bench.js'
 
 expose({
   exposedFunction (data) {
index 3a33592841d81567f73f6975052f6ba885e800e6..41f6fd797156b94fc890c530efb9c8e7109480bd 100644 (file)
@@ -1,2 +1,2 @@
-import functionToBench from '../../functions/function-to-bench.mjs'
+import functionToBench from '../../functions/function-to-bench.js'
 export default functionToBench
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..3f3fc23
--- /dev/null
@@ -0,0 +1,2 @@
+const functionToBench = require('../../functions/function-to-bench')
+module.exports = functionToBench
diff --git a/benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.mjs b/benchmarks/versus-external-pools/workers/worker-nodes/function-to-bench-worker.mjs
deleted file mode 100644 (file)
index afa4ce1..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-import functionToBench from '../../functions/function-to-bench.mjs'
-export { functionToBench }
index d8981c8689916ef820dae21ed12f5f91df0436fe..c49013c3efd19eaa78618d3d41086b246a384a4b 100644 (file)
@@ -1,5 +1,5 @@
 import workerpool from 'workerpool'
-import functionToBench from '../../functions/function-to-bench.mjs'
+import functionToBench from '../../functions/function-to-bench.js'
 
 function wrapperFunctionToBench (testName, taskType, taskSize) {
   return functionToBench({