From: Jérôme Benoit Date: Sun, 16 Apr 2023 21:37:43 +0000 (+0200) Subject: refactor: cleanup internal benchmark code X-Git-Tag: v2.4.11~39 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=cdace0e5b9082804893de9501372490ee1064090;p=poolifier.git refactor: cleanup internal benchmark code Signed-off-by: Jérôme Benoit --- diff --git a/benchmarks/benchmarks-types.js b/benchmarks/benchmarks-types.js index 91380343..7a951fee 100644 --- a/benchmarks/benchmarks-types.js +++ b/benchmarks/benchmarks-types.js @@ -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 } diff --git a/benchmarks/benchmarks-utils.js b/benchmarks/benchmarks-utils.js index 6eed668b..50dcc40c 100644 --- a/benchmarks/benchmarks-utils.js +++ b/benchmarks/benchmarks-utils.js @@ -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 } diff --git a/benchmarks/internal/bench.js b/benchmarks/internal/bench.js index fb2fb07f..4c126a00 100644 --- a/benchmarks/internal/bench.js +++ b/benchmarks/internal/bench.js @@ -1,108 +1,331 @@ 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(), diff --git a/benchmarks/internal/cluster/worker.js b/benchmarks/internal/cluster-worker.js similarity index 66% rename from benchmarks/internal/cluster/worker.js rename to benchmarks/internal/cluster-worker.js index 926278be..a4742a28 100644 --- a/benchmarks/internal/cluster/worker.js +++ b/benchmarks/internal/cluster-worker.js @@ -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 index 475ba9d7..00000000 --- a/benchmarks/internal/cluster/dynamic.js +++ /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 index 5469c443..00000000 --- a/benchmarks/internal/cluster/fixed.js +++ /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 -} diff --git a/benchmarks/internal/thread/worker.js b/benchmarks/internal/thread-worker.js similarity index 67% rename from benchmarks/internal/thread/worker.js rename to benchmarks/internal/thread-worker.js index 09060eba..38958181 100644 --- a/benchmarks/internal/thread/worker.js +++ b/benchmarks/internal/thread-worker.js @@ -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 index 503ea27c..00000000 --- a/benchmarks/internal/thread/dynamic.js +++ /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 index c8be6feb..00000000 --- a/benchmarks/internal/thread/fixed.js +++ /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 -} diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 54f9382a..2ea4649b 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -5,7 +5,7 @@ const { FixedThreadPool, PoolEvents, WorkerChoiceStrategies -} = require('../../../lib/index') +} = require('../../../lib') const { CircularArray } = require('../../../lib/circular-array') describe('Abstract pool test suite', () => { diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index 23403ab7..e67d92bd 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@ -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') diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index d84c2c5c..21dcd78b 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -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') diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index b5d59032..f5d41cc8 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -4,7 +4,7 @@ const { DynamicThreadPool, FixedThreadPool, FixedClusterPool -} = require('../../../lib/index') +} = require('../../../lib') describe('Selection strategies test suite', () => { const min = 0 diff --git a/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js b/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js index 05f0bb4c..8e59d81e 100644 --- a/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js +++ b/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js @@ -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') diff --git a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js b/tests/pools/selection-strategies/worker-choice-strategy-context.test.js index 0fd3fb71..79bcf2a1 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js +++ b/tests/pools/selection-strategies/worker-choice-strategy-context.test.js @@ -4,7 +4,7 @@ const { FixedThreadPool, DynamicThreadPool, WorkerChoiceStrategies -} = require('../../../lib/index') +} = require('../../../lib') const { WorkerChoiceStrategyContext } = require('../../../lib/pools/selection-strategies/worker-choice-strategy-context') diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index 29ce0152..3e5a2d35 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -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') diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index f2b36fa7..1d07e0c7 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -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') diff --git a/tests/worker-files/cluster/asyncErrorWorker.js b/tests/worker-files/cluster/asyncErrorWorker.js index 02daa5b5..09278851 100644 --- a/tests/worker-files/cluster/asyncErrorWorker.js +++ b/tests/worker-files/cluster/asyncErrorWorker.js @@ -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) { diff --git a/tests/worker-files/cluster/asyncWorker.js b/tests/worker-files/cluster/asyncWorker.js index b9ad419f..e8866877 100644 --- a/tests/worker-files/cluster/asyncWorker.js +++ b/tests/worker-files/cluster/asyncWorker.js @@ -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) { diff --git a/tests/worker-files/cluster/echoWorker.js b/tests/worker-files/cluster/echoWorker.js index 9bcae281..f9308c70 100644 --- a/tests/worker-files/cluster/echoWorker.js +++ b/tests/worker-files/cluster/echoWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { ClusterWorker, KillBehaviors } = require('../../../lib/index') +const { ClusterWorker, KillBehaviors } = require('../../../lib') function echo (data) { return data diff --git a/tests/worker-files/cluster/emptyWorker.js b/tests/worker-files/cluster/emptyWorker.js index a0c94085..01d1cf09 100644 --- a/tests/worker-files/cluster/emptyWorker.js +++ b/tests/worker-files/cluster/emptyWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { ClusterWorker, KillBehaviors } = require('../../../lib/index') +const { ClusterWorker, KillBehaviors } = require('../../../lib') function test () {} diff --git a/tests/worker-files/cluster/errorWorker.js b/tests/worker-files/cluster/errorWorker.js index bea29f41..01cffc5e 100644 --- a/tests/worker-files/cluster/errorWorker.js +++ b/tests/worker-files/cluster/errorWorker.js @@ -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') diff --git a/tests/worker-files/cluster/longRunningWorkerHardBehavior.js b/tests/worker-files/cluster/longRunningWorkerHardBehavior.js index ec08d425..005699e9 100644 --- a/tests/worker-files/cluster/longRunningWorkerHardBehavior.js +++ b/tests/worker-files/cluster/longRunningWorkerHardBehavior.js @@ -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) { diff --git a/tests/worker-files/cluster/longRunningWorkerSoftBehavior.js b/tests/worker-files/cluster/longRunningWorkerSoftBehavior.js index c1e89e1a..5c6fdf42 100644 --- a/tests/worker-files/cluster/longRunningWorkerSoftBehavior.js +++ b/tests/worker-files/cluster/longRunningWorkerSoftBehavior.js @@ -1,5 +1,5 @@ 'use strict' -const { ClusterWorker } = require('../../../lib/index') +const { ClusterWorker } = require('../../../lib') const TestUtils = require('../../test-utils') async function sleep (data) { diff --git a/tests/worker-files/cluster/testWorker.js b/tests/worker-files/cluster/testWorker.js index 4c31e3ad..ee82c654 100644 --- a/tests/worker-files/cluster/testWorker.js +++ b/tests/worker-files/cluster/testWorker.js @@ -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') diff --git a/tests/worker-files/thread/asyncErrorWorker.js b/tests/worker-files/thread/asyncErrorWorker.js index b960997f..ac966330 100644 --- a/tests/worker-files/thread/asyncErrorWorker.js +++ b/tests/worker-files/thread/asyncErrorWorker.js @@ -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) { diff --git a/tests/worker-files/thread/asyncWorker.js b/tests/worker-files/thread/asyncWorker.js index 2191a12e..5af97b07 100644 --- a/tests/worker-files/thread/asyncWorker.js +++ b/tests/worker-files/thread/asyncWorker.js @@ -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) { diff --git a/tests/worker-files/thread/echoWorker.js b/tests/worker-files/thread/echoWorker.js index cfe9427b..998e56b2 100644 --- a/tests/worker-files/thread/echoWorker.js +++ b/tests/worker-files/thread/echoWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { ThreadWorker, KillBehaviors } = require('../../../lib/index') +const { ThreadWorker, KillBehaviors } = require('../../../lib') function echo (data) { return data diff --git a/tests/worker-files/thread/emptyWorker.js b/tests/worker-files/thread/emptyWorker.js index 191c0331..cb076770 100644 --- a/tests/worker-files/thread/emptyWorker.js +++ b/tests/worker-files/thread/emptyWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { ThreadWorker, KillBehaviors } = require('../../../lib/index') +const { ThreadWorker, KillBehaviors } = require('../../../lib') function test () {} diff --git a/tests/worker-files/thread/errorWorker.js b/tests/worker-files/thread/errorWorker.js index c4937c93..19785dc3 100644 --- a/tests/worker-files/thread/errorWorker.js +++ b/tests/worker-files/thread/errorWorker.js @@ -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') diff --git a/tests/worker-files/thread/longRunningWorkerHardBehavior.js b/tests/worker-files/thread/longRunningWorkerHardBehavior.js index a295da7b..29c633bb 100644 --- a/tests/worker-files/thread/longRunningWorkerHardBehavior.js +++ b/tests/worker-files/thread/longRunningWorkerHardBehavior.js @@ -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) { diff --git a/tests/worker-files/thread/longRunningWorkerSoftBehavior.js b/tests/worker-files/thread/longRunningWorkerSoftBehavior.js index 2c7b03b7..c6fa5393 100644 --- a/tests/worker-files/thread/longRunningWorkerSoftBehavior.js +++ b/tests/worker-files/thread/longRunningWorkerSoftBehavior.js @@ -1,5 +1,5 @@ 'use strict' -const { ThreadWorker } = require('../../../lib/index') +const { ThreadWorker } = require('../../../lib') const TestUtils = require('../../test-utils') async function sleep (data) { diff --git a/tests/worker-files/thread/testWorker.js b/tests/worker-files/thread/testWorker.js index f843329f..2b86fde2 100644 --- a/tests/worker-files/thread/testWorker.js +++ b/tests/worker-files/thread/testWorker.js @@ -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')