1 import Benchmark from 'benny'
2 import { WorkerChoiceStrategies } from '../../lib/index.mjs'
7 } from '../benchmarks-types.mjs'
8 import { buildPool, runTest } from '../benchmarks-utils.mjs'
11 const taskExecutions = 1
13 function: WorkerFunctions.jsonIntegerSerialization,
16 const tasksQueuePoolOption = { enableTasksQueue: true }
17 const workerChoiceStrategyRoundRobinPoolOption = {
18 workerChoiceStrategy: WorkerChoiceStrategies.ROUND_ROBIN
20 const workerChoiceStrategyLeastUsedPoolOption = {
21 workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED
23 const workerChoiceStrategyLeastBusyPoolOption = {
24 workerChoiceStrategy: WorkerChoiceStrategies.LEAST_BUSY
26 const workerChoiceStrategyWeightedRoundRobinPoolOption = {
27 workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
29 const workerChoiceStrategyFairSharePoolOption = {
30 workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE
33 const fixedThreadPoolRoundRobin = buildPool(
37 workerChoiceStrategyRoundRobinPoolOption
40 const fixedThreadPoolRoundRobinTasksQueue = buildPool(
44 { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
47 const fixedThreadPoolLeastUsed = buildPool(
51 workerChoiceStrategyLeastUsedPoolOption
54 const fixedThreadPoolLeastBusy = buildPool(
58 workerChoiceStrategyLeastBusyPoolOption
61 const fixedThreadPoolWeightedRoundRobin = buildPool(
65 workerChoiceStrategyWeightedRoundRobinPoolOption
68 const fixedThreadPoolFairShare = buildPool(
72 workerChoiceStrategyFairSharePoolOption
75 const fixedThreadPoolFairShareTasksQueue = buildPool(
79 { ...workerChoiceStrategyFairSharePoolOption, ...tasksQueuePoolOption }
82 const dynamicThreadPoolRoundRobin = buildPool(
86 workerChoiceStrategyRoundRobinPoolOption
89 const dynamicThreadPoolLeastUsed = buildPool(
93 workerChoiceStrategyLeastUsedPoolOption
96 const dynamicThreadPoolLeastBusy = buildPool(
100 workerChoiceStrategyLeastBusyPoolOption
103 const dynamicThreadPoolWeightedRoundRobin = buildPool(
107 workerChoiceStrategyWeightedRoundRobinPoolOption
110 const dynamicThreadPoolFairShare = buildPool(
114 workerChoiceStrategyFairSharePoolOption
117 const fixedClusterPoolRoundRobin = buildPool(
121 workerChoiceStrategyRoundRobinPoolOption
124 const fixedClusterPoolRoundRobinTasksQueue = buildPool(
128 { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
131 const fixedClusterPoolLeastUsed = buildPool(
135 workerChoiceStrategyLeastUsedPoolOption
138 const fixedClusterPoolLeastBusy = buildPool(
142 workerChoiceStrategyLeastBusyPoolOption
145 const fixedClusterPoolWeightedRoundRobin = buildPool(
149 workerChoiceStrategyWeightedRoundRobinPoolOption
152 const fixedClusterPoolFairShare = buildPool(
156 workerChoiceStrategyFairSharePoolOption
159 const fixedClusterPoolFairShareTaskQueue = buildPool(
163 { ...workerChoiceStrategyFairSharePoolOption, ...tasksQueuePoolOption }
166 const dynamicClusterPoolRoundRobin = buildPool(
170 workerChoiceStrategyRoundRobinPoolOption
173 const dynamicClusterPoolLeastUsed = buildPool(
177 workerChoiceStrategyLeastUsedPoolOption
180 const dynamicClusterPoolLeastBusy = buildPool(
184 workerChoiceStrategyLeastBusyPoolOption
187 const dynamicClusterPoolWeightedRoundRobin = buildPool(
191 workerChoiceStrategyWeightedRoundRobinPoolOption
194 const dynamicClusterPoolFairShare = buildPool(
198 workerChoiceStrategyFairSharePoolOption
201 const resultsFile = 'poolifier'
202 const resultsFolder = 'benchmarks/internal/results'
206 Benchmark.add('Fixed:ThreadPool:RoundRobin', async () => {
207 await runTest(fixedThreadPoolRoundRobin, {
213 'Fixed:ThreadPool:RoundRobin:{ enableTasksQueue: true }',
215 await runTest(fixedThreadPoolRoundRobinTasksQueue, {
221 Benchmark.add('Fixed:ThreadPool:LeastUsed', async () => {
222 await runTest(fixedThreadPoolLeastUsed, {
227 Benchmark.add('Fixed:ThreadPool:LeastBusy', async () => {
228 await runTest(fixedThreadPoolLeastBusy, {
233 Benchmark.add('Fixed:ThreadPool:WeightedRoundRobin', async () => {
234 await runTest(fixedThreadPoolWeightedRoundRobin, {
239 Benchmark.add('Fixed:ThreadPool:FairShare', async () => {
240 await runTest(fixedThreadPoolFairShare, {
246 'Fixed:ThreadPool:FairShare:{ enableTasksQueue: true }',
248 await runTest(fixedThreadPoolFairShareTasksQueue, {
254 Benchmark.add('Dynamic:ThreadPool:RoundRobin', async () => {
255 await runTest(dynamicThreadPoolRoundRobin, {
260 Benchmark.add('Dynamic:ThreadPool:LeastUsed', async () => {
261 await runTest(dynamicThreadPoolLeastUsed, {
266 Benchmark.add('Dynamic:ThreadPool:LeastBusy', async () => {
267 await runTest(dynamicThreadPoolLeastBusy, {
272 Benchmark.add('Dynamic:ThreadPool:WeightedRoundRobin', async () => {
273 await runTest(dynamicThreadPoolWeightedRoundRobin, {
278 Benchmark.add('Dynamic:ThreadPool:FairShare', async () => {
279 await runTest(dynamicThreadPoolFairShare, {
284 Benchmark.add('Fixed:ClusterPool:RoundRobin', async () => {
285 await runTest(fixedClusterPoolRoundRobin, {
291 'Fixed:ClusterPool:RoundRobin:{ enableTasksQueue: true }',
293 await runTest(fixedClusterPoolRoundRobinTasksQueue, {
299 Benchmark.add('Fixed:ClusterPool:LeastUsed', async () => {
300 await runTest(fixedClusterPoolLeastUsed, {
305 Benchmark.add('Fixed:ClusterPool:LeastBusy', async () => {
306 await runTest(fixedClusterPoolLeastBusy, {
311 Benchmark.add('Fixed:ClusterPool:WeightedRoundRobin', async () => {
312 await runTest(fixedClusterPoolWeightedRoundRobin, {
317 Benchmark.add('Fixed:ClusterPool:FairShare', async () => {
318 await runTest(fixedClusterPoolFairShare, {
324 'Fixed:ClusterPool:FairShare:{ enableTasksQueue: true }',
326 await runTest(fixedClusterPoolFairShareTaskQueue, {
332 Benchmark.add('Dynamic:ClusterPool:RoundRobin', async () => {
333 await runTest(dynamicClusterPoolRoundRobin, {
338 Benchmark.add('Dynamic:ClusterPool:LeastUsed', async () => {
339 await runTest(dynamicClusterPoolLeastUsed, {
344 Benchmark.add('Dynamic:ClusterPool:LeastBusy', async () => {
345 await runTest(dynamicClusterPoolLeastBusy, {
350 Benchmark.add('Dynamic:ClusterPool:WeightedRoundRobin', async () => {
351 await runTest(dynamicClusterPoolWeightedRoundRobin, {
356 Benchmark.add('Dynamic:ClusterPool:FairShare', async () => {
357 await runTest(dynamicClusterPoolFairShare, {
363 Benchmark.complete(),
366 folder: resultsFolder,
372 folder: resultsFolder,
373 format: 'chart.html',
378 folder: resultsFolder,
379 format: 'table.html',
384 // eslint-disable-next-line n/no-process-exit
385 return process.exit()
387 .catch(err => console.error(err))