Benchmarks: properly parse env variables
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 20 Oct 2022 14:58:06 +0000 (16:58 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 20 Oct 2022 14:58:06 +0000 (16:58 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
16 files changed:
benchmarks/versus-external-pools/dynamic-piscina.js
benchmarks/versus-external-pools/dynamic-poolifier.js
benchmarks/versus-external-pools/dynamic-suchmokuo-node-worker-threads-pool.js
benchmarks/versus-external-pools/dynamic-worker-nodes.js
benchmarks/versus-external-pools/dynamic-workerpool.js
benchmarks/versus-external-pools/fixed-microjob.js
benchmarks/versus-external-pools/fixed-piscina.js
benchmarks/versus-external-pools/fixed-poolifier.js
benchmarks/versus-external-pools/fixed-threadwork.js
benchmarks/versus-external-pools/fixed-worker-nodes.js
benchmarks/versus-external-pools/fixed-workerpool.js
benchmarks/versus-external-pools/pool-threadwork.js
benchmarks/versus-external-pools/static-suchmokuo-node-worker-threads-pool.js
benchmarks/versus-external-pools/threadjs.js
src/pools/abstract-pool.ts
src/worker/abstract-worker.ts

index 7f707004345fda6330c9402a6b8398330ba8c7a7..6b835d0ee37239460ca81c00564292da647cb224 100644 (file)
@@ -1,12 +1,12 @@
 // IMPORT LIBRARIES
 const Piscina = require('piscina')
 // FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env.TASK_TYPE,
-  taskSize: process.env.TASK_SIZE
+  taskSize: parseInt(process.env.TASK_SIZE)
 }
 
 const piscina = new Piscina({
index 197169a58b734d3e8a33e17f62e0d7aeb62b40ea..206284212eb5d40ff264fc004d7d5d32be408ca7 100644 (file)
@@ -1,12 +1,12 @@
 // IMPORT LIBRARIES
 const { DynamicThreadPool } = require('poolifier')
 // FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env.TASK_TYPE,
-  taskSize: process.env.TASK_SIZE
+  taskSize: parseInt(process.env.TASK_SIZE)
 }
 
 const dynamicPool = new DynamicThreadPool(
index c65ffdeae8037fc0762b26fd3d9e0ed506d60877..0a56d1fd2326555ca7804d4850efb87670a517f2 100644 (file)
@@ -4,12 +4,12 @@ const { DynamicPool } = require('node-worker-threads-pool')
 // IMPORT FUNCTION TO BENCH
 const functionToBench = require('./functions/function-to-bench')
 // FINISH IMPORT FUNCTION TO BENCH
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env.TASK_TYPE,
-  taskSize: process.env.TASK_SIZE
+  taskSize: parseInt(process.env.TASK_SIZE)
 }
 
 const pool = new DynamicPool(size)
index 0c665f8597a26625e457091240766829ec53e4c2..47484528791f03c61211bb1f813562892e7de2b2 100644 (file)
@@ -1,12 +1,12 @@
 // 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 size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env.TASK_TYPE,
-  taskSize: process.env.TASK_SIZE
+  taskSize: parseInt(process.env.TASK_SIZE)
 }
 
 const workerNodes = new WorkerNodes(
index 996522d392b8db8e5b15cd429379aebbde004afb..04d90ab209f4365968b6d7ecf2a6d130ed74779e 100644 (file)
@@ -1,9 +1,13 @@
 // IMPORT LIBRARIES
 const workerpool = require('workerpool')
 // FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
-const dataArray = ['MYBENCH', process.env.TASK_TYPE, process.env.TASK_SIZE]
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
+const dataArray = [
+  'MYBENCH',
+  process.env.TASK_TYPE,
+  parseInt(process.env.TASK_SIZE)
+]
 
 const workerPool = workerpool.pool(
   './workers/workerpool/function-to-bench-worker.js',
index dd0280688e630a6ed26ad53070da03fd29ee7ff0..b61dcd9438b70e029cb3890adb695761e5dbebeb 100644 (file)
@@ -4,12 +4,12 @@ const { job, start } = require('microjob')
 // IMPORT FUNCTION TO BENCH
 const functionToBench = require('./functions/function-to-bench')
 // FINISH IMPORT FUNCTION TO BENCH
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env.TASK_TYPE,
-  taskSize: process.env.TASK_SIZE
+  taskSize: parseInt(process.env.TASK_SIZE)
 }
 
 async function run () {
index fc8a87c147d0f3f9269d6cb7ea3a462aff73f985..8a92dbea5b6a7709f8b2df90b77f7a8ce170d394 100644 (file)
@@ -1,12 +1,12 @@
 // IMPORT LIBRARIES
 const Piscina = require('piscina')
 // FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env.TASK_TYPE,
-  taskSize: process.env.TASK_SIZE
+  taskSize: parseInt(process.env.TASK_SIZE)
 }
 
 const piscina = new Piscina({
index fbfd484ea51dc3a48f371a7a535a669659c41e05..2a5e599ab11aefc0948bb8ec208f3650ede4e02f 100644 (file)
@@ -1,12 +1,12 @@
 // IMPORT LIBRARIES
 const { FixedThreadPool } = require('poolifier')
 // FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env.TASK_TYPE,
-  taskSize: process.env.TASK_SIZE
+  taskSize: parseInt(process.env.TASK_SIZE)
 }
 
 const fixedPool = new FixedThreadPool(
index cb9c3ca09be88ff6f20bf6819f245b3d94aac6ce..d21fae6a8e2179704af88fb420c40f2c338deb1a 100644 (file)
@@ -1,11 +1,11 @@
 // IMPORT LIBRARIES
 const threadPool = require('./pool-threadwork')
 // FINISH IMPORT LIBRARIES
-const iterations = Number(process.env.NUM_ITERATIONS)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env.TASK_TYPE,
-  taskSize: process.env.TASK_SIZE
+  taskSize: parseInt(process.env.TASK_SIZE)
 }
 
 async function run () {
index a720f197fff52b58497a500a505bf7c62b75a628..49f8637ded36feb2e43b2d3796607622b1ae7fc0 100644 (file)
@@ -1,12 +1,12 @@
 // 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 size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env.TASK_TYPE,
-  taskSize: process.env.TASK_SIZE
+  taskSize: parseInt(process.env.TASK_SIZE)
 }
 
 const workerNodes = new WorkerNodes(
index 499c17a5c4003e44d2f8fb6103249c00d2b18cb4..cabdd9e794545c79e8a88ccc6e11eeb5ebd81ff7 100644 (file)
@@ -1,9 +1,13 @@
 // IMPORT LIBRARIES
 const workerpool = require('workerpool')
 // FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
-const dataArray = ['MYBENCH', process.env.TASK_TYPE, process.env.TASK_SIZE]
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
+const dataArray = [
+  'MYBENCH',
+  process.env.TASK_TYPE,
+  parseInt(process.env.TASK_SIZE)
+]
 
 const workerPool = workerpool.pool(
   './workers/workerpool/function-to-bench-worker.js',
index 36baad1f4ea2414b39ca13e04a332e4e5966ad90..2a2844f0e447d1fdf25608b53e63386b4e008232 100644 (file)
@@ -4,6 +4,6 @@ const { ThreadPool } = require('threadwork')
 // IMPORT FUNCTION TO BENCH
 const functionToBench = require('./functions/function-to-bench')
 // FINISH IMPORT FUNCTION TO BENCH
-const size = Number(process.env.POOL_SIZE)
+const size = parseInt(process.env.POOL_SIZE)
 
 module.exports = new ThreadPool({ task: functionToBench, size })
index 1c8f0d7f1bb2ece8a945682e0470334550a179db..75f3d2a438fd3cc1b1a963e626f6b2cccecff69d 100644 (file)
@@ -4,12 +4,12 @@ const { StaticPool } = require('node-worker-threads-pool')
 // IMPORT FUNCTION TO BENCH
 const functionToBench = require('./functions/function-to-bench')
 // FINISH IMPORT FUNCTION TO BENCH
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env.TASK_TYPE,
-  taskSize: process.env.TASK_SIZE
+  taskSize: parseInt(process.env.TASK_SIZE)
 }
 
 const pool = new StaticPool({
index b6b3a5fa8c5f1047a018b00b855f2bba02009196..ee9178e92b7954663efd9855f069476423d6bb06 100644 (file)
@@ -1,12 +1,12 @@
 // IMPORT LIBRARIES
 const { spawn, Worker } = require('threads')
 // FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
 const data = {
   test: 'MYBENCH',
   taskType: process.env.TASK_TYPE,
-  taskSize: process.env.TASK_SIZE
+  taskSize: parseInt(process.env.TASK_SIZE)
 }
 
 // Threads.js is not really a pool so we need to write few additional code
index 40e06b158fe3af59ec49527a6cc170822520657f..346eb6d1fdb02cdf992f84b91502ae21f465800e 100644 (file)
@@ -85,7 +85,7 @@ export abstract class AbstractPool<
     public readonly filePath: string,
     public readonly opts: PoolOptions<Worker>
   ) {
-    if (!this.isMain()) {
+    if (this.isMain() === false) {
       throw new Error('Cannot start a pool from a worker!')
     }
     this.checkNumberOfWorkers(this.numberOfWorkers)
@@ -97,7 +97,7 @@ export abstract class AbstractPool<
       this.createAndSetupWorker()
     }
 
-    if (this.opts.enableEvents) {
+    if (this.opts.enableEvents === true) {
       this.emitter = new PoolEmitter()
     }
     this.workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
@@ -380,7 +380,7 @@ export abstract class AbstractPool<
   }
 
   private checkAndEmitBusy (): void {
-    if (this.opts.enableEvents && this.busy) {
+    if (this.opts.enableEvents === true && this.busy === true) {
       this.emitter?.emit('busy')
     }
   }
index 9ec38feda57cdccc6cde6598943c2b157e439ed4..3090b6f534f29597e7dca3dabddee8935f46ddbe 100644 (file)
@@ -84,7 +84,7 @@ export abstract class AbstractWorker<
   ): void {
     if (value.data !== undefined && value.id !== undefined) {
       // Here you will receive messages
-      if (this.opts.async) {
+      if (this.opts.async === true) {
         this.runInAsyncScope(this.runAsync.bind(this), this, fn, value)
       } else {
         this.runInAsyncScope(this.run.bind(this), this, fn, value)