refactor: cleanup internal benchmark code
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 16 Apr 2023 21:37:43 +0000 (23:37 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 16 Apr 2023 21:37:43 +0000 (23:37 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
33 files changed:
benchmarks/benchmarks-types.js
benchmarks/benchmarks-utils.js
benchmarks/internal/bench.js
benchmarks/internal/cluster-worker.js [moved from benchmarks/internal/cluster/worker.js with 66% similarity]
benchmarks/internal/cluster/dynamic.js [deleted file]
benchmarks/internal/cluster/fixed.js [deleted file]
benchmarks/internal/thread-worker.js [moved from benchmarks/internal/thread/worker.js with 67% similarity]
benchmarks/internal/thread/dynamic.js [deleted file]
benchmarks/internal/thread/fixed.js [deleted file]
tests/pools/abstract/abstract-pool.test.js
tests/pools/cluster/dynamic.test.js
tests/pools/cluster/fixed.test.js
tests/pools/selection-strategies/selection-strategies.test.js
tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js
tests/pools/selection-strategies/worker-choice-strategy-context.test.js
tests/pools/thread/dynamic.test.js
tests/pools/thread/fixed.test.js
tests/worker-files/cluster/asyncErrorWorker.js
tests/worker-files/cluster/asyncWorker.js
tests/worker-files/cluster/echoWorker.js
tests/worker-files/cluster/emptyWorker.js
tests/worker-files/cluster/errorWorker.js
tests/worker-files/cluster/longRunningWorkerHardBehavior.js
tests/worker-files/cluster/longRunningWorkerSoftBehavior.js
tests/worker-files/cluster/testWorker.js
tests/worker-files/thread/asyncErrorWorker.js
tests/worker-files/thread/asyncWorker.js
tests/worker-files/thread/echoWorker.js
tests/worker-files/thread/emptyWorker.js
tests/worker-files/thread/errorWorker.js
tests/worker-files/thread/longRunningWorkerHardBehavior.js
tests/worker-files/thread/longRunningWorkerSoftBehavior.js
tests/worker-files/thread/testWorker.js

index 913803437597b46556f26e5dae46159b16dc7627..7a951feece39d6580286f40201f5a51119248f31 100644 (file)
@@ -1,7 +1,18 @@
 const WorkerFunctions = {
   jsonIntegerSerialization: 'jsonIntegerSerialization',
   fibonacci: 'fibonacci',
-  factorial: 'factorial'
+  factorial: 'factorial',
+  readWriteFiles: 'readWriteFiles'
 }
 
-module.exports = { WorkerFunctions }
+const PoolTypes = {
+  FIXED: 'fixed',
+  DYNAMIC: 'dynamic'
+}
+
+const WorkerTypes = {
+  THREAD: 'thread',
+  CLUSTER: 'cluster'
+}
+
+module.exports = { PoolTypes, WorkerFunctions, WorkerTypes }
index 6eed668bd16b33d9f7f6598ed2a680285d884e36..50dcc40c6edaff1a45d885c7c0dd5d531efe3ae6 100644 (file)
@@ -1,14 +1,25 @@
-const { WorkerFunctions } = require('./benchmarks-types')
+const fs = require('fs')
+const {
+  PoolTypes,
+  WorkerFunctions,
+  WorkerTypes
+} = require('./benchmarks-types')
+const {
+  DynamicClusterPool,
+  DynamicThreadPool,
+  FixedClusterPool,
+  FixedThreadPool
+} = require('../lib')
 
-async function runPoolifierTest (pool, { tasks, workerData }) {
+async function runTest (pool, { taskExecutions, workerData }) {
   return new Promise((resolve, reject) => {
     let executions = 0
-    for (let i = 1; i <= tasks; i++) {
+    for (let i = 1; i <= taskExecutions; i++) {
       pool
         .execute(workerData)
         .then(() => {
           ++executions
-          if (executions === tasks) {
+          if (executions === taskExecutions) {
             return resolve({ ok: 1 })
           }
           return null
@@ -21,15 +32,6 @@ async function runPoolifierTest (pool, { tasks, workerData }) {
   })
 }
 
-function jsonIntegerSerialization (n) {
-  for (let i = 0; i < n; i++) {
-    const o = {
-      a: i
-    }
-    JSON.stringify(o)
-  }
-}
-
 function generateRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
   if (max < min || max < 0 || min < 0) {
     throw new RangeError('Invalid interval')
@@ -42,6 +44,15 @@ function generateRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
   return Math.floor(Math.random() * (max + 1))
 }
 
+function jsonIntegerSerialization (n) {
+  for (let i = 0; i < n; i++) {
+    const o = {
+      a: i
+    }
+    JSON.stringify(o)
+  }
+}
+
 /**
  * Intentionally inefficient implementation.
  *
@@ -66,6 +77,21 @@ function factorial (n) {
   return factorial(n - 1) * n
 }
 
+function readWriteFiles (n) {
+  const baseDirectory = '/tmp/poolifier-benchmarks'
+  if (fs.existsSync(baseDirectory) === false) {
+    fs.mkdirSync(baseDirectory, { recursive: true })
+  }
+  for (let i = 0; i < n; i++) {
+    const filePath = `${baseDirectory}/${i}`
+    fs.writeFileSync(filePath, i.toString(), {
+      encoding: 'utf8',
+      flag: 'a'
+    })
+    fs.readFileSync(filePath, 'utf8')
+  }
+}
+
 function executeWorkerFunction (data) {
   switch (data.function) {
     case WorkerFunctions.jsonIntegerSerialization:
@@ -74,14 +100,57 @@ function executeWorkerFunction (data) {
       return fibonacci(data.taskSize || 1000)
     case WorkerFunctions.factorial:
       return factorial(data.taskSize || 1000)
+    case WorkerFunctions.readWriteFiles:
+      return readWriteFiles(data.taskSize || 1000)
     default:
       throw new Error('Unknown worker function')
   }
 }
 
+function buildPool (poolType, poolSize, workerType, poolOptions) {
+  switch (poolType) {
+    case PoolTypes.FIXED:
+      switch (workerType) {
+        case WorkerTypes.THREAD:
+          return new FixedThreadPool(
+            poolSize,
+            './benchmarks/internal/thread-worker.js',
+            poolOptions
+          )
+        case WorkerTypes.CLUSTER:
+          return new FixedClusterPool(
+            poolSize,
+            './benchmarks/internal/cluster-worker.js',
+            poolOptions
+          )
+      }
+      break
+    case PoolTypes.DYNAMIC:
+      switch (workerType) {
+        case WorkerTypes.THREAD:
+          return new DynamicThreadPool(
+            poolSize / 2,
+            poolSize * 3,
+            './benchmarks/internal/thread-worker.js',
+            poolOptions
+          )
+        case WorkerTypes.CLUSTER:
+          return new DynamicClusterPool(
+            poolSize / 2,
+            poolSize * 3,
+            './benchmarks/internal/cluster-worker.js',
+            poolOptions
+          )
+      }
+      break
+  }
+}
+
 module.exports = {
   WorkerFunctions,
+  buildPool,
   executeWorkerFunction,
   generateRandomInteger,
-  runPoolifierTest
+  readWriteFiles,
+  runTest
 }
index fb2fb07f36351a88a3f8190e1b3c13c16f488f09..4c126a00fb9d531011b71cb52e459c2aa017b695 100644 (file)
 const Benchmark = require('benny')
+const { WorkerChoiceStrategies } = require('../../lib')
 const {
-  dynamicClusterTest,
-  dynamicClusterTestFairShare,
-  dynamicClusterTestLessUsed,
-  dynamicClusterTestWeightedRoundRobin,
-  dynamicClusterTestLessBusy
-} = require('./cluster/dynamic')
-const {
-  fixedClusterTest,
-  fixedClusterTasksQueueTest,
-  fixedClusterTestFairShare,
-  fixedClusterTestLessUsed,
-  fixedClusterTestWeightedRoundRobin,
-  fixedClusterTestLessBusy
-} = require('./cluster/fixed')
-const {
-  dynamicThreadTest,
-  dynamicThreadTestFairShare,
-  dynamicThreadTestLessUsed,
-  dynamicThreadTestWeightedRoundRobin,
-  dynamicThreadTestLessBusy
-} = require('./thread/dynamic')
-const {
-  fixedThreadTest,
-  fixedThreadTasksQueueTest,
-  fixedThreadTestFairShare,
-  fixedThreadTestLessUsed,
-  fixedThreadTestWeightedRoundRobin,
-  fixedThreadTestLessBusy
-} = require('./thread/fixed')
+  PoolTypes,
+  WorkerFunctions,
+  WorkerTypes
+} = require('../benchmarks-types')
+const { buildPool, runTest } = require('../benchmarks-utils')
+
+const poolSize = 30
+const taskExecutions = 1
+const workerData = {
+  function: WorkerFunctions.jsonIntegerSerialization,
+  taskSize: 1000
+}
+const tasksQueuePoolOption = { enableTasksQueue: true }
+const workerChoiceStrategyRoundRobinPoolOption = {
+  workerChoiceStrategy: WorkerChoiceStrategies.ROUND_ROBIN
+}
+const workerChoiceStrategyLessUsedPoolOption = {
+  workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED
+}
+const workerChoiceStrategyLessBusyPoolOption = {
+  workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY
+}
+const workerChoiceStrategyWeightedRoundRobinPoolOption = {
+  workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+}
+const workerChoiceStrategyFairSharePoolOption = {
+  workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE
+}
+
+const fixedThreadPoolRoundRobin = buildPool(
+  PoolTypes.FIXED,
+  poolSize,
+  WorkerTypes.THREAD,
+  workerChoiceStrategyRoundRobinPoolOption
+)
+
+const fixedThreadPoolRoundRobinTasksQueue = buildPool(
+  PoolTypes.FIXED,
+  poolSize,
+  WorkerTypes.THREAD,
+  { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
+)
+
+const fixedThreadPoolLessUsed = buildPool(
+  PoolTypes.FIXED,
+  poolSize,
+  WorkerTypes.THREAD,
+  workerChoiceStrategyLessUsedPoolOption
+)
+
+const fixedThreadPoolLessBusy = buildPool(
+  PoolTypes.FIXED,
+  poolSize,
+  WorkerTypes.THREAD,
+  workerChoiceStrategyLessBusyPoolOption
+)
+
+const fixedThreadPoolWeightedRoundRobin = buildPool(
+  PoolTypes.FIXED,
+  poolSize,
+  WorkerTypes.THREAD,
+  workerChoiceStrategyWeightedRoundRobinPoolOption
+)
+
+const fixedThreadPoolFairShare = buildPool(
+  PoolTypes.FIXED,
+  poolSize,
+  WorkerTypes.THREAD,
+  workerChoiceStrategyFairSharePoolOption
+)
+
+const dynamicThreadPoolRoundRobin = buildPool(
+  PoolTypes.DYNAMIC,
+  poolSize,
+  WorkerTypes.THREAD,
+  workerChoiceStrategyRoundRobinPoolOption
+)
+
+const dynamicThreadPoolLessUsed = buildPool(
+  PoolTypes.DYNAMIC,
+  poolSize,
+  WorkerTypes.THREAD,
+  workerChoiceStrategyLessUsedPoolOption
+)
+
+const dynamicThreadPoolLessBusy = buildPool(
+  PoolTypes.DYNAMIC,
+  poolSize,
+  WorkerTypes.THREAD,
+  workerChoiceStrategyLessBusyPoolOption
+)
+
+const dynamicThreadPoolWeightedRoundRobin = buildPool(
+  PoolTypes.DYNAMIC,
+  poolSize,
+  WorkerTypes.THREAD,
+  workerChoiceStrategyWeightedRoundRobinPoolOption
+)
+
+const dynamicThreadPoolFairShare = buildPool(
+  PoolTypes.DYNAMIC,
+  poolSize,
+  WorkerTypes.THREAD,
+  workerChoiceStrategyFairSharePoolOption
+)
+
+const fixedClusterPoolRoundRobin = buildPool(
+  PoolTypes.FIXED,
+  poolSize,
+  WorkerTypes.CLUSTER,
+  workerChoiceStrategyRoundRobinPoolOption
+)
+
+const fixedClusterPoolRoundRobinTasksQueue = buildPool(
+  PoolTypes.FIXED,
+  poolSize,
+  WorkerTypes.CLUSTER,
+  { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
+)
+
+const fixedClusterPoolLessUsed = buildPool(
+  PoolTypes.FIXED,
+  poolSize,
+  WorkerTypes.CLUSTER,
+  workerChoiceStrategyLessUsedPoolOption
+)
+
+const fixedClusterPoolLessBusy = buildPool(
+  PoolTypes.FIXED,
+  poolSize,
+  WorkerTypes.CLUSTER,
+  workerChoiceStrategyLessBusyPoolOption
+)
+
+const fixedClusterPoolWeightedRoundRobin = buildPool(
+  PoolTypes.FIXED,
+  poolSize,
+  WorkerTypes.CLUSTER,
+  workerChoiceStrategyWeightedRoundRobinPoolOption
+)
+
+const fixedClusterPoolFairShare = buildPool(
+  PoolTypes.FIXED,
+  poolSize,
+  WorkerTypes.CLUSTER,
+  workerChoiceStrategyFairSharePoolOption
+)
+
+const dynamicClusterPoolRoundRobin = buildPool(
+  PoolTypes.DYNAMIC,
+  poolSize,
+  WorkerTypes.CLUSTER,
+  workerChoiceStrategyRoundRobinPoolOption
+)
+
+const dynamicClusterPoolLessUsed = buildPool(
+  PoolTypes.DYNAMIC,
+  poolSize,
+  WorkerTypes.CLUSTER,
+  workerChoiceStrategyLessUsedPoolOption
+)
+
+const dynamicClusterPoolLessBusy = buildPool(
+  PoolTypes.DYNAMIC,
+  poolSize,
+  WorkerTypes.CLUSTER,
+  workerChoiceStrategyLessBusyPoolOption
+)
+
+const dynamicClusterPoolWeightedRoundRobin = buildPool(
+  PoolTypes.DYNAMIC,
+  poolSize,
+  WorkerTypes.CLUSTER,
+  workerChoiceStrategyWeightedRoundRobinPoolOption
+)
+
+const dynamicClusterPoolFairShare = buildPool(
+  PoolTypes.DYNAMIC,
+  poolSize,
+  WorkerTypes.CLUSTER,
+  workerChoiceStrategyFairSharePoolOption
+)
 
 const resultsFile = 'poolifier'
 const resultsFolder = 'benchmarks/internal/results'
 
 Benchmark.suite(
   'Poolifier',
-  Benchmark.add('Poolifier:Fixed:ThreadPool', async () => {
-    await fixedThreadTest()
+  Benchmark.add('Fixed:ThreadPool:RoundRobin', async () => {
+    await runTest(fixedThreadPoolRoundRobin, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Fixed:ThreadPoolTasksQueue', async () => {
-    await fixedThreadTasksQueueTest()
-  }),
-  Benchmark.add('Poolifier:Fixed:ThreadPool:LessUsed', async () => {
-    await fixedThreadTestLessUsed()
+  Benchmark.add(
+    'Fixed:ThreadPool:RoundRobin:{ enableTasksQueue: true }',
+    async () => {
+      await runTest(fixedThreadPoolRoundRobinTasksQueue, {
+        taskExecutions,
+        workerData
+      })
+    }
+  ),
+  Benchmark.add('Fixed:ThreadPool:LessUsed', async () => {
+    await runTest(fixedThreadPoolLessUsed, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Fixed:ThreadPool:LessBusy', async () => {
-    await fixedThreadTestLessBusy()
+  Benchmark.add('Fixed:ThreadPool:LessBusy', async () => {
+    await runTest(fixedThreadPoolLessBusy, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Fixed:ThreadPool:WeightedRoundRobin', async () => {
-    await fixedThreadTestWeightedRoundRobin()
+  Benchmark.add('Fixed:ThreadPool:WeightedRoundRobin', async () => {
+    await runTest(fixedThreadPoolWeightedRoundRobin, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Fixed:ThreadPool:FairShare', async () => {
-    await fixedThreadTestFairShare()
+  Benchmark.add('Fixed:ThreadPool:FairShare', async () => {
+    await runTest(fixedThreadPoolFairShare, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Dynamic:ThreadPool', async () => {
-    await dynamicThreadTest()
+  Benchmark.add('Dynamic:ThreadPool:RoundRobin', async () => {
+    await runTest(dynamicThreadPoolRoundRobin, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Dynamic:ThreadPool:LessUsed', async () => {
-    await dynamicThreadTestLessUsed()
+  Benchmark.add('Dynamic:ThreadPool:LessUsed', async () => {
+    await runTest(dynamicThreadPoolLessUsed, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Dynamic:ThreadPool:LessBusy', async () => {
-    await dynamicThreadTestLessBusy()
+  Benchmark.add('Dynamic:ThreadPool:LessBusy', async () => {
+    await runTest(dynamicThreadPoolLessBusy, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Dynamic:ThreadPool:WeightedRoundRobin', async () => {
-    await dynamicThreadTestWeightedRoundRobin()
+  Benchmark.add('Dynamic:ThreadPool:WeightedRoundRobin', async () => {
+    await runTest(dynamicThreadPoolWeightedRoundRobin, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Dynamic:ThreadPool:FairShare', async () => {
-    await dynamicThreadTestFairShare()
+  Benchmark.add('Dynamic:ThreadPool:FairShare', async () => {
+    await runTest(dynamicThreadPoolFairShare, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Fixed:ClusterPool', async () => {
-    await fixedClusterTest()
+  Benchmark.add('Fixed:ClusterPool:RoundRobin', async () => {
+    await runTest(fixedClusterPoolRoundRobin, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Fixed:ClusterPoolTasksQueue', async () => {
-    await fixedClusterTasksQueueTest()
+  Benchmark.add(
+    'Fixed:ClusterPool:RoundRobin:{ enableTasksQueue: true }',
+    async () => {
+      await runTest(fixedClusterPoolRoundRobinTasksQueue, {
+        taskExecutions,
+        workerData
+      })
+    }
+  ),
+  Benchmark.add('Fixed:ClusterPool:LessUsed', async () => {
+    await runTest(fixedClusterPoolLessUsed, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Fixed:ClusterPool:LessUsed', async () => {
-    await fixedClusterTestLessUsed()
+  Benchmark.add('Fixed:ClusterPool:LessBusy', async () => {
+    await runTest(fixedClusterPoolLessBusy, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Fixed:ClusterPool:LessBusy', async () => {
-    await fixedClusterTestLessBusy()
+  Benchmark.add('Fixed:ClusterPool:WeightedRoundRobin', async () => {
+    await runTest(fixedClusterPoolWeightedRoundRobin, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Fixed:ClusterPool:WeightedRoundRobin', async () => {
-    await fixedClusterTestWeightedRoundRobin()
+  Benchmark.add('Fixed:ClusterPool:FairShare', async () => {
+    await runTest(fixedClusterPoolFairShare, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Fixed:ClusterPool:FairShare', async () => {
-    await fixedClusterTestFairShare()
+  Benchmark.add('Dynamic:ClusterPool:RoundRobin', async () => {
+    await runTest(dynamicClusterPoolRoundRobin, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Dynamic:ClusterPool', async () => {
-    await dynamicClusterTest()
+  Benchmark.add('Dynamic:ClusterPool:LessUsed', async () => {
+    await runTest(dynamicClusterPoolLessUsed, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Dynamic:ClusterPool:LessUsed', async () => {
-    await dynamicClusterTestLessUsed()
+  Benchmark.add('Dynamic:ClusterPool:LessBusy', async () => {
+    await runTest(dynamicClusterPoolLessBusy, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add('Poolifier:Dynamic:ClusterPool:LessBusy', async () => {
-    await dynamicClusterTestLessBusy()
+  Benchmark.add('Dynamic:ClusterPool:WeightedRoundRobin', async () => {
+    await runTest(dynamicClusterPoolWeightedRoundRobin, {
+      taskExecutions,
+      workerData
+    })
   }),
-  Benchmark.add(
-    'Poolifier:Dynamic:ClusterPool:WeightedRoundRobin',
-    async () => {
-      await dynamicClusterTestWeightedRoundRobin()
-    }
-  ),
-  Benchmark.add('Poolifier:Dynamic:ClusterPool:FairShare', async () => {
-    await dynamicClusterTestFairShare()
+  Benchmark.add('Dynamic:ClusterPool:FairShare', async () => {
+    await runTest(dynamicClusterPoolFairShare, {
+      taskExecutions,
+      workerData
+    })
   }),
   Benchmark.cycle(),
   Benchmark.complete(),
similarity index 66%
rename from benchmarks/internal/cluster/worker.js
rename to benchmarks/internal/cluster-worker.js
index 926278be77e4484fbbd9200af2b48fa76db27f26..a4742a28d43fafe7fe1e21e2e0b6cfe3932805c8 100644 (file)
@@ -1,8 +1,8 @@
 'use strict'
 const { isMaster } = require('cluster')
-const { ClusterWorker } = require('../../../lib/index')
-const { executeWorkerFunction } = require('../../benchmarks-utils')
-const { WorkerFunctions } = require('../../benchmarks-types')
+const { ClusterWorker } = require('../../lib')
+const { executeWorkerFunction } = require('../benchmarks-utils')
+const { WorkerFunctions } = require('../benchmarks-types')
 
 const debug = false
 
diff --git a/benchmarks/internal/cluster/dynamic.js b/benchmarks/internal/cluster/dynamic.js
deleted file mode 100644 (file)
index 475ba9d..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-const {
-  DynamicClusterPool,
-  WorkerChoiceStrategies
-} = require('../../../lib/index')
-const { runPoolifierTest } = require('../../benchmarks-utils')
-
-const size = 30
-const numberOfTasks = 1
-
-const dynamicPool = new DynamicClusterPool(
-  size / 2,
-  size * 3,
-  './benchmarks/internal/cluster/worker.js'
-)
-
-const dynamicPoolLessUsed = new DynamicClusterPool(
-  size / 2,
-  size * 3,
-  './benchmarks/internal/cluster/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
-)
-
-const dynamicPoolLessBusy = new DynamicClusterPool(
-  size / 2,
-  size * 3,
-  './benchmarks/internal/cluster/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
-)
-
-const dynamicPoolWeightedRoundRobin = new DynamicClusterPool(
-  size / 2,
-  size * 3,
-  './benchmarks/internal/cluster/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
-)
-
-const dynamicPoolFairShare = new DynamicClusterPool(
-  size / 2,
-  size * 3,
-  './benchmarks/internal/cluster/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
-)
-
-async function dynamicClusterTest (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(dynamicPool, { tasks, workerData })
-}
-
-async function dynamicClusterTestLessUsed (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(dynamicPoolLessUsed, { tasks, workerData })
-}
-
-async function dynamicClusterTestLessBusy (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(dynamicPoolLessBusy, { tasks, workerData })
-}
-
-async function dynamicClusterTestWeightedRoundRobin (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(dynamicPoolWeightedRoundRobin, { tasks, workerData })
-}
-
-async function dynamicClusterTestFairShare (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(dynamicPoolFairShare, { tasks, workerData })
-}
-
-module.exports = {
-  dynamicClusterTest,
-  dynamicClusterTestLessUsed,
-  dynamicClusterTestLessBusy,
-  dynamicClusterTestWeightedRoundRobin,
-  dynamicClusterTestFairShare
-}
diff --git a/benchmarks/internal/cluster/fixed.js b/benchmarks/internal/cluster/fixed.js
deleted file mode 100644 (file)
index 5469c44..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-const {
-  FixedClusterPool,
-  WorkerChoiceStrategies
-} = require('../../../lib/index')
-const { runPoolifierTest } = require('../../benchmarks-utils')
-
-const size = 30
-const numberOfTasks = 1
-
-const fixedPool = new FixedClusterPool(
-  size,
-  './benchmarks/internal/cluster/worker.js'
-)
-
-const fixedPoolTasksQueue = new FixedClusterPool(
-  size,
-  './benchmarks/internal/cluster/worker.js',
-  { enableTasksQueue: true }
-)
-
-const fixedPoolLessUsed = new FixedClusterPool(
-  size,
-  './benchmarks/internal/cluster/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
-)
-
-const fixedPoolLessBusy = new FixedClusterPool(
-  size,
-  './benchmarks/internal/cluster/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
-)
-
-const fixedPoolWeightedRoundRobin = new FixedClusterPool(
-  size,
-  './benchmarks/internal/cluster/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
-)
-
-const fixedPoolFairShare = new FixedClusterPool(
-  size,
-  './benchmarks/internal/cluster/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
-)
-
-async function fixedClusterTest (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(fixedPool, { tasks, workerData })
-}
-
-async function fixedClusterTasksQueueTest (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(fixedPoolTasksQueue, { tasks, workerData })
-}
-
-async function fixedClusterTestLessUsed (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(fixedPoolLessUsed, { tasks, workerData })
-}
-
-async function fixedClusterTestLessBusy (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(fixedPoolLessBusy, { tasks, workerData })
-}
-
-async function fixedClusterTestWeightedRoundRobin (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(fixedPoolWeightedRoundRobin, { tasks, workerData })
-}
-
-async function fixedClusterTestFairShare (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(fixedPoolFairShare, { tasks, workerData })
-}
-
-module.exports = {
-  fixedClusterTest,
-  fixedClusterTasksQueueTest,
-  fixedClusterTestLessUsed,
-  fixedClusterTestLessBusy,
-  fixedClusterTestWeightedRoundRobin,
-  fixedClusterTestFairShare
-}
similarity index 67%
rename from benchmarks/internal/thread/worker.js
rename to benchmarks/internal/thread-worker.js
index 09060ebad46032264aea8dd3f60df085cba81b8c..389581813eb552f846d8c95221b6c37989fd12e7 100644 (file)
@@ -1,8 +1,8 @@
 'use strict'
 const { isMainThread } = require('worker_threads')
-const { ThreadWorker } = require('../../../lib/index')
-const { executeWorkerFunction } = require('../../benchmarks-utils')
-const { WorkerFunctions } = require('../../benchmarks-types')
+const { ThreadWorker } = require('../../lib')
+const { executeWorkerFunction } = require('../benchmarks-utils')
+const { WorkerFunctions } = require('../benchmarks-types')
 
 const debug = false
 
diff --git a/benchmarks/internal/thread/dynamic.js b/benchmarks/internal/thread/dynamic.js
deleted file mode 100644 (file)
index 503ea27..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-const {
-  DynamicThreadPool,
-  WorkerChoiceStrategies
-} = require('../../../lib/index')
-const { runPoolifierTest } = require('../../benchmarks-utils')
-
-const size = 30
-const numberOfTasks = 1
-
-const dynamicPool = new DynamicThreadPool(
-  size / 2,
-  size * 3,
-  './benchmarks/internal/thread/worker.js'
-)
-
-const dynamicPoolLessUsed = new DynamicThreadPool(
-  size / 2,
-  size * 3,
-  './benchmarks/internal/thread/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
-)
-
-const dynamicPoolLessBusy = new DynamicThreadPool(
-  size / 2,
-  size * 3,
-  './benchmarks/internal/thread/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
-)
-
-const dynamicPoolWeightedRoundRobin = new DynamicThreadPool(
-  size / 2,
-  size * 3,
-  './benchmarks/internal/thread/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
-)
-
-const dynamicPoolFairShare = new DynamicThreadPool(
-  size / 2,
-  size * 3,
-  './benchmarks/internal/thread/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
-)
-
-async function dynamicThreadTest (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(dynamicPool, { tasks, workerData })
-}
-
-async function dynamicThreadTestLessUsed (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(dynamicPoolLessUsed, { tasks, workerData })
-}
-
-async function dynamicThreadTestLessBusy (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(dynamicPoolLessBusy, { tasks, workerData })
-}
-
-async function dynamicThreadTestWeightedRoundRobin (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(dynamicPoolWeightedRoundRobin, { tasks, workerData })
-}
-
-async function dynamicThreadTestFairShare (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(dynamicPoolFairShare, { tasks, workerData })
-}
-
-module.exports = {
-  dynamicThreadTest,
-  dynamicThreadTestLessUsed,
-  dynamicThreadTestLessBusy,
-  dynamicThreadTestWeightedRoundRobin,
-  dynamicThreadTestFairShare
-}
diff --git a/benchmarks/internal/thread/fixed.js b/benchmarks/internal/thread/fixed.js
deleted file mode 100644 (file)
index c8be6fe..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-const {
-  FixedThreadPool,
-  WorkerChoiceStrategies
-} = require('../../../lib/index')
-const { runPoolifierTest } = require('../../benchmarks-utils')
-
-const size = 30
-const numberOfTasks = 1
-
-const fixedPool = new FixedThreadPool(
-  size,
-  './benchmarks/internal/thread/worker.js'
-)
-
-const fixedPoolTasksQueue = new FixedThreadPool(
-  size,
-  './benchmarks/internal/thread/worker.js',
-  { enableTasksQueue: true }
-)
-
-const fixedPoolLessUsed = new FixedThreadPool(
-  size,
-  './benchmarks/internal/thread/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
-)
-
-const fixedPoolLessBusy = new FixedThreadPool(
-  size,
-  './benchmarks/internal/thread/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
-)
-
-const fixedPoolWeightedRoundRobin = new FixedThreadPool(
-  size,
-  './benchmarks/internal/thread/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
-)
-
-const fixedPoolFairShare = new FixedThreadPool(
-  size,
-  './benchmarks/internal/thread/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
-)
-
-async function fixedThreadTest (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(fixedPool, { tasks, workerData })
-}
-
-async function fixedThreadTasksQueueTest (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(fixedPoolTasksQueue, { tasks, workerData })
-}
-
-async function fixedThreadTestLessUsed (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(fixedPoolLessUsed, { tasks, workerData })
-}
-
-async function fixedThreadTestLessBusy (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(fixedPoolLessBusy, { tasks, workerData })
-}
-
-async function fixedThreadTestWeightedRoundRobin (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(fixedPoolWeightedRoundRobin, { tasks, workerData })
-}
-
-async function fixedThreadTestFairShare (
-  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
-  return runPoolifierTest(fixedPoolFairShare, { tasks, workerData })
-}
-
-module.exports = {
-  fixedThreadTest,
-  fixedThreadTasksQueueTest,
-  fixedThreadTestLessUsed,
-  fixedThreadTestLessBusy,
-  fixedThreadTestWeightedRoundRobin,
-  fixedThreadTestFairShare
-}
index 54f9382ab9c7d8f0064d699fa0c7a56bba8a4295..2ea4649baedb03a74930eea37a1d39bbfdcea4de 100644 (file)
@@ -5,7 +5,7 @@ const {
   FixedThreadPool,
   PoolEvents,
   WorkerChoiceStrategies
-} = require('../../../lib/index')
+} = require('../../../lib')
 const { CircularArray } = require('../../../lib/circular-array')
 
 describe('Abstract pool test suite', () => {
index 23403ab78108620f555d8d9d8635cb06bcafd1e8..e67d92bdb9849d05c09801a865e548a8208a4470 100644 (file)
@@ -1,5 +1,5 @@
 const { expect } = require('expect')
-const { DynamicClusterPool, PoolEvents } = require('../../../lib/index')
+const { DynamicClusterPool, PoolEvents } = require('../../../lib')
 const { WorkerFunctions } = require('../../test-types')
 const TestUtils = require('../../test-utils')
 
index d84c2c5c3f727e6b639a7c5eca00941931fae6ca..21dcd78bfeb6f3016eb5826025198329a4f244c7 100644 (file)
@@ -1,5 +1,5 @@
 const { expect } = require('expect')
-const { FixedClusterPool, PoolEvents } = require('../../../lib/index')
+const { FixedClusterPool, PoolEvents } = require('../../../lib')
 const { WorkerFunctions } = require('../../test-types')
 const TestUtils = require('../../test-utils')
 
index b5d5903226b9979d0b455548a603eb4df3608512..f5d41cc89927d1e7468273daa2fa4e80c87c8b73 100644 (file)
@@ -4,7 +4,7 @@ const {
   DynamicThreadPool,
   FixedThreadPool,
   FixedClusterPool
-} = require('../../../lib/index')
+} = require('../../../lib')
 
 describe('Selection strategies test suite', () => {
   const min = 0
index 05f0bb4c3a6497c246a52621e16c9a8d62430739..8e59d81e192d89f5d51dfbab18fdc62be3b5827c 100644 (file)
@@ -1,6 +1,6 @@
 const { expect } = require('expect')
 const sinon = require('sinon')
-const { FixedThreadPool } = require('../../../lib/index')
+const { FixedThreadPool } = require('../../../lib')
 const {
   WeightedRoundRobinWorkerChoiceStrategy
 } = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy')
index 0fd3fb71bfc48a17834375d14ba596d901f9761a..79bcf2a165eabfcad1c224ff83824336a0a95fec 100644 (file)
@@ -4,7 +4,7 @@ const {
   FixedThreadPool,
   DynamicThreadPool,
   WorkerChoiceStrategies
-} = require('../../../lib/index')
+} = require('../../../lib')
 const {
   WorkerChoiceStrategyContext
 } = require('../../../lib/pools/selection-strategies/worker-choice-strategy-context')
index 29ce01529b9a18710ef261fa87eb1d5604fb7de0..3e5a2d354fe8d76c5d0c73013a8a2957d5ff7d52 100644 (file)
@@ -1,5 +1,5 @@
 const { expect } = require('expect')
-const { DynamicThreadPool, PoolEvents } = require('../../../lib/index')
+const { DynamicThreadPool, PoolEvents } = require('../../../lib')
 const { WorkerFunctions } = require('../../test-types')
 const TestUtils = require('../../test-utils')
 
index f2b36fa7d9eeb617919c86dcdbbf1d797f7e777e..1d07e0c7ca8c24dce32a340ffff31c49c1326aa6 100644 (file)
@@ -1,5 +1,5 @@
 const { expect } = require('expect')
-const { FixedThreadPool, PoolEvents } = require('../../../lib/index')
+const { FixedThreadPool, PoolEvents } = require('../../../lib')
 const { WorkerFunctions } = require('../../test-types')
 const TestUtils = require('../../test-utils')
 
index 02daa5b5a1f3ee77d1eab04a5dcbc281bc0dd639..09278851c72e31070e31784447ad8cda0e637a56 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
 const TestUtils = require('../../test-utils')
 
 async function error (data) {
index b9ad419f82f97e61646ecd6c35cbb89ab9b6ec83..e8866877c0ec2ac6d8f5aed1ce70666ddac85b13 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
 const TestUtils = require('../../test-utils')
 
 async function sleep (data) {
index 9bcae28163bf475972f334623505e4a23531ed64..f9308c70c4bbbecfa0d205db06867a46562e2ac2 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
 
 function echo (data) {
   return data
index a0c94085897af10321a34427c076d4f7cdad01e5..01d1cf09812e4baf8584e5fc41f9920b7d1db2a0 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
 
 function test () {}
 
index bea29f4192eed2fb72f346b388dd61566df71ada..01cffc5e47641a74297f0ac1e11542eaf4f8e4d9 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
 
 function error () {
   throw new Error('Error Message from ClusterWorker')
index ec08d42540de16f50f3ad6b08eb8dc1bb7826b03..005699e92195beafe6c24bcbfeb1938e823f8efe 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
 const TestUtils = require('../../test-utils')
 
 async function sleep (data) {
index c1e89e1a5150558af4b42338fae23c3d6ec66f3a..5c6fdf42679b72a7e213ce098240363016cf366c 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ClusterWorker } = require('../../../lib/index')
+const { ClusterWorker } = require('../../../lib')
 const TestUtils = require('../../test-utils')
 
 async function sleep (data) {
index 4c31e3ad9125decdd56b103e9f80f35531325ec3..ee82c654705b26eb830faa3c407cd6092b4731e9 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
 const { isMaster } = require('cluster')
 const TestUtils = require('../../test-utils')
 const { WorkerFunctions } = require('../../test-types')
index b960997f807e499883097cc51c7bde94f5ad19c6..ac9663304c101eb49504fe8ce989c7610228afe8 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
 const TestUtils = require('../../test-utils')
 
 async function error (data) {
index 2191a12e85240de96646fc2d2dfd4d10622ab5d0..5af97b0734e6da16643b763a785d4069e6f48522 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
 const TestUtils = require('../../test-utils')
 
 async function sleep (data) {
index cfe9427bdf6fa44c684a5861e18d81d1905aae42..998e56b20b108899fadd7000b414885dcd4c33b6 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
 
 function echo (data) {
   return data
index 191c033127e46ea054c5d425948e3c50a8df47c4..cb076770c8f59183d24b4504453ac3157d371079 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
 
 function test () {}
 
index c4937c93ce9f1b45603bd0cfbef82d605602b3c3..19785dc36152b694d16e62468504590f9e921cb2 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
 
 function error () {
   throw new Error('Error Message from ThreadWorker')
index a295da7bc647aa7ab5e49ab432d92096f11968a6..29c633bbb2d2bb3f12163a70cc2adfe4c7481306 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
 const TestUtils = require('../../test-utils')
 
 async function sleep (data) {
index 2c7b03b7109081ba16e6e76510c992b056fac872..c6fa5393f44830bd9e8af28dabc473ad6198d8b3 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ThreadWorker } = require('../../../lib/index')
+const { ThreadWorker } = require('../../../lib')
 const TestUtils = require('../../test-utils')
 
 async function sleep (data) {
index f843329f296b17ae295eb3c58beeeb284b3e3b71..2b86fde282c6ed28106656164d7af1275b479b00 100644 (file)
@@ -1,5 +1,5 @@
 'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
 const { isMainThread } = require('worker_threads')
 const TestUtils = require('../../test-utils')
 const { WorkerFunctions } = require('../../test-types')