X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fbench.mjs;h=564a4de14621bf6bd096e7fc940753f8eb6ee0d9;hb=5b95eb9bcafda56ce57003da834cf4e153bb0509;hp=26cc81c339f1d2dbf41385eb86884a36e31b3e28;hpb=d33d2d2fed43d102479c38cc28b496872665a90d;p=poolifier.git diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 26cc81c3..564a4de1 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -1,390 +1,133 @@ -import Benchmark from 'benny' -import { - WorkerChoiceStrategies, - availableParallelism -} from '../../lib/index.mjs' +import { exit } from 'node:process' +import { parseArgs } from 'node:util' + +import { run } from 'mitata' + import { + availableParallelism, PoolTypes, - WorkerFunctions, WorkerTypes -} from '../benchmarks-types.mjs' -import { buildPool, runTest } from '../benchmarks-utils.mjs' +} from '../../lib/index.mjs' +import { TaskFunctions } from '../benchmarks-types.cjs' +import { + buildPoolifierBenchmarkMitata, + runPoolifierBenchmarkBenchmarkJsSuite +} from '../benchmarks-utils.mjs' const poolSize = availableParallelism() const taskExecutions = 1 const workerData = { - function: WorkerFunctions.jsonIntegerSerialization, - taskSize: 1000 + function: TaskFunctions.factorial, + taskSize: 50000 } -const tasksQueuePoolOption = { enableTasksQueue: true } -const workerChoiceStrategyRoundRobinPoolOption = { - workerChoiceStrategy: WorkerChoiceStrategies.ROUND_ROBIN -} -const workerChoiceStrategyLeastUsedPoolOption = { - workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED -} -const workerChoiceStrategyLeastBusyPoolOption = { - workerChoiceStrategy: WorkerChoiceStrategies.LEAST_BUSY -} -const workerChoiceStrategyWeightedRoundRobinPoolOption = { - workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN -} -const workerChoiceStrategyFairSharePoolOption = { - workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE -} - -const fixedThreadPoolRoundRobin = buildPool( - WorkerTypes.thread, - PoolTypes.fixed, - poolSize, - workerChoiceStrategyRoundRobinPoolOption -) - -const fixedThreadPoolRoundRobinTasksQueue = buildPool( - WorkerTypes.thread, - PoolTypes.fixed, - poolSize, - { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption } -) - -const fixedThreadPoolLeastUsed = buildPool( - WorkerTypes.thread, - PoolTypes.fixed, - poolSize, - workerChoiceStrategyLeastUsedPoolOption -) - -const fixedThreadPoolLeastBusy = buildPool( - WorkerTypes.thread, - PoolTypes.fixed, - poolSize, - workerChoiceStrategyLeastBusyPoolOption -) - -const fixedThreadPoolWeightedRoundRobin = buildPool( - WorkerTypes.thread, - PoolTypes.fixed, - poolSize, - workerChoiceStrategyWeightedRoundRobinPoolOption -) - -const fixedThreadPoolFairShare = buildPool( - WorkerTypes.thread, - PoolTypes.fixed, - poolSize, - workerChoiceStrategyFairSharePoolOption -) - -const fixedThreadPoolFairShareTasksQueue = buildPool( - WorkerTypes.thread, - PoolTypes.fixed, - poolSize, - { ...workerChoiceStrategyFairSharePoolOption, ...tasksQueuePoolOption } -) - -const dynamicThreadPoolRoundRobin = buildPool( - WorkerTypes.thread, - PoolTypes.dynamic, - poolSize, - workerChoiceStrategyRoundRobinPoolOption -) - -const dynamicThreadPoolLeastUsed = buildPool( - WorkerTypes.thread, - PoolTypes.dynamic, - poolSize, - workerChoiceStrategyLeastUsedPoolOption -) - -const dynamicThreadPoolLeastBusy = buildPool( - WorkerTypes.thread, - PoolTypes.dynamic, - poolSize, - workerChoiceStrategyLeastBusyPoolOption -) - -const dynamicThreadPoolWeightedRoundRobin = buildPool( - WorkerTypes.thread, - PoolTypes.dynamic, - poolSize, - workerChoiceStrategyWeightedRoundRobinPoolOption -) - -const dynamicThreadPoolFairShare = buildPool( - WorkerTypes.thread, - PoolTypes.dynamic, - poolSize, - workerChoiceStrategyFairSharePoolOption -) -const fixedClusterPoolRoundRobin = buildPool( - WorkerTypes.cluster, - PoolTypes.fixed, - poolSize, - workerChoiceStrategyRoundRobinPoolOption -) - -const fixedClusterPoolRoundRobinTasksQueue = buildPool( - WorkerTypes.cluster, - PoolTypes.fixed, - poolSize, - { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption } -) - -const fixedClusterPoolLeastUsed = buildPool( - WorkerTypes.cluster, - PoolTypes.fixed, - poolSize, - workerChoiceStrategyLeastUsedPoolOption -) - -const fixedClusterPoolLeastBusy = buildPool( - WorkerTypes.cluster, - PoolTypes.fixed, - poolSize, - workerChoiceStrategyLeastBusyPoolOption -) - -const fixedClusterPoolWeightedRoundRobin = buildPool( - WorkerTypes.cluster, - PoolTypes.fixed, - poolSize, - workerChoiceStrategyWeightedRoundRobinPoolOption -) - -const fixedClusterPoolFairShare = buildPool( - WorkerTypes.cluster, - PoolTypes.fixed, - poolSize, - workerChoiceStrategyFairSharePoolOption -) - -const fixedClusterPoolFairShareTaskQueue = buildPool( - WorkerTypes.cluster, - PoolTypes.fixed, - poolSize, - { ...workerChoiceStrategyFairSharePoolOption, ...tasksQueuePoolOption } -) - -const dynamicClusterPoolRoundRobin = buildPool( - WorkerTypes.cluster, - PoolTypes.dynamic, - poolSize, - workerChoiceStrategyRoundRobinPoolOption -) - -const dynamicClusterPoolLeastUsed = buildPool( - WorkerTypes.cluster, - PoolTypes.dynamic, - poolSize, - workerChoiceStrategyLeastUsedPoolOption -) - -const dynamicClusterPoolLeastBusy = buildPool( - WorkerTypes.cluster, - PoolTypes.dynamic, - poolSize, - workerChoiceStrategyLeastBusyPoolOption -) - -const dynamicClusterPoolWeightedRoundRobin = buildPool( - WorkerTypes.cluster, - PoolTypes.dynamic, - poolSize, - workerChoiceStrategyWeightedRoundRobinPoolOption -) - -const dynamicClusterPoolFairShare = buildPool( - WorkerTypes.cluster, - PoolTypes.dynamic, - poolSize, - workerChoiceStrategyFairSharePoolOption -) - -const resultsFile = 'poolifier' -const resultsFolder = 'benchmarks/internal/results' - -Benchmark.suite( - 'Poolifier', - Benchmark.add('Fixed:ThreadPool:RoundRobin', async () => { - await runTest(fixedThreadPoolRoundRobin, { - taskExecutions, - workerData - }) - }), - Benchmark.add( - 'Fixed:ThreadPool:RoundRobin:{ enableTasksQueue: true }', - async () => { - await runTest(fixedThreadPoolRoundRobinTasksQueue, { +let fixedThreadPool +let dynamicThreadPool +let fixedClusterPool +let dynamicClusterPool +switch ( + parseArgs({ + args: process.argv, + options: { + type: { + type: 'string', + short: 't' + } + }, + strict: true, + allowPositionals: true + }).values.type +) { + case 'mitata': + fixedThreadPool = buildPoolifierBenchmarkMitata( + 'FixedThreadPool', + WorkerTypes.thread, + PoolTypes.fixed, + poolSize, + { + taskExecutions, + workerData + } + ) + dynamicThreadPool = buildPoolifierBenchmarkMitata( + 'DynamicThreadPool', + WorkerTypes.thread, + PoolTypes.dynamic, + poolSize, + { taskExecutions, workerData - }) - } - ), - Benchmark.add('Fixed:ThreadPool:LeastUsed', async () => { - await runTest(fixedThreadPoolLeastUsed, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Fixed:ThreadPool:LeastBusy', async () => { - await runTest(fixedThreadPoolLeastBusy, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Fixed:ThreadPool:WeightedRoundRobin', async () => { - await runTest(fixedThreadPoolWeightedRoundRobin, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Fixed:ThreadPool:FairShare', async () => { - await runTest(fixedThreadPoolFairShare, { - taskExecutions, - workerData - }) - }), - Benchmark.add( - 'Fixed:ThreadPool:FairShare:{ enableTasksQueue: true }', - async () => { - await runTest(fixedThreadPoolFairShareTasksQueue, { + } + ) + fixedClusterPool = buildPoolifierBenchmarkMitata( + 'FixedClusterPool', + WorkerTypes.cluster, + PoolTypes.fixed, + poolSize, + { taskExecutions, workerData - }) - } - ), - Benchmark.add('Dynamic:ThreadPool:RoundRobin', async () => { - await runTest(dynamicThreadPoolRoundRobin, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Dynamic:ThreadPool:LeastUsed', async () => { - await runTest(dynamicThreadPoolLeastUsed, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Dynamic:ThreadPool:LeastBusy', async () => { - await runTest(dynamicThreadPoolLeastBusy, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Dynamic:ThreadPool:WeightedRoundRobin', async () => { - await runTest(dynamicThreadPoolWeightedRoundRobin, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Dynamic:ThreadPool:FairShare', async () => { - await runTest(dynamicThreadPoolFairShare, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Fixed:ClusterPool:RoundRobin', async () => { - await runTest(fixedClusterPoolRoundRobin, { - taskExecutions, - workerData - }) - }), - Benchmark.add( - 'Fixed:ClusterPool:RoundRobin:{ enableTasksQueue: true }', - async () => { - await runTest(fixedClusterPoolRoundRobinTasksQueue, { + } + ) + dynamicClusterPool = buildPoolifierBenchmarkMitata( + 'DynamicClusterPool', + WorkerTypes.cluster, + PoolTypes.dynamic, + poolSize, + { taskExecutions, workerData - }) - } - ), - Benchmark.add('Fixed:ClusterPool:LeastUsed', async () => { - await runTest(fixedClusterPoolLeastUsed, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Fixed:ClusterPool:LeastBusy', async () => { - await runTest(fixedClusterPoolLeastBusy, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Fixed:ClusterPool:WeightedRoundRobin', async () => { - await runTest(fixedClusterPoolWeightedRoundRobin, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Fixed:ClusterPool:FairShare', async () => { - await runTest(fixedClusterPoolFairShare, { - taskExecutions, - workerData - }) - }), - Benchmark.add( - 'Fixed:ClusterPool:FairShare:{ enableTasksQueue: true }', - async () => { - await runTest(fixedClusterPoolFairShareTaskQueue, { + } + ) + await run() + await fixedThreadPool.destroy() + await dynamicThreadPool.destroy() + await fixedClusterPool.destroy() + await dynamicClusterPool.destroy() + break + case 'benchmark.js': + default: + await runPoolifierBenchmarkBenchmarkJsSuite( + 'FixedThreadPool', + WorkerTypes.thread, + PoolTypes.fixed, + poolSize, + { taskExecutions, workerData - }) - } - ), - Benchmark.add('Dynamic:ClusterPool:RoundRobin', async () => { - await runTest(dynamicClusterPoolRoundRobin, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Dynamic:ClusterPool:LeastUsed', async () => { - await runTest(dynamicClusterPoolLeastUsed, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Dynamic:ClusterPool:LeastBusy', async () => { - await runTest(dynamicClusterPoolLeastBusy, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Dynamic:ClusterPool:WeightedRoundRobin', async () => { - await runTest(dynamicClusterPoolWeightedRoundRobin, { - taskExecutions, - workerData - }) - }), - Benchmark.add('Dynamic:ClusterPool:FairShare', async () => { - await runTest(dynamicClusterPoolFairShare, { - taskExecutions, - workerData - }) - }), - Benchmark.cycle(), - Benchmark.complete(), - Benchmark.save({ - file: resultsFile, - folder: resultsFolder, - format: 'json', - details: true - }), - Benchmark.save({ - file: resultsFile, - folder: resultsFolder, - format: 'chart.html', - details: true - }), - Benchmark.save({ - file: resultsFile, - folder: resultsFolder, - format: 'table.html', - details: true - }) -) - .then(() => { - // eslint-disable-next-line n/no-process-exit - return process.exit() - }) - .catch(err => console.error(err)) + } + ) + await runPoolifierBenchmarkBenchmarkJsSuite( + 'DynamicThreadPool', + WorkerTypes.thread, + PoolTypes.dynamic, + poolSize, + { + taskExecutions, + workerData + } + ) + await runPoolifierBenchmarkBenchmarkJsSuite( + 'FixedClusterPool', + WorkerTypes.cluster, + PoolTypes.fixed, + poolSize, + { + taskExecutions, + workerData + } + ) + await runPoolifierBenchmarkBenchmarkJsSuite( + 'DynamicClusterPool', + WorkerTypes.cluster, + PoolTypes.dynamic, + poolSize, + { + taskExecutions, + workerData + } + ) + break +} + +exit()