1 import Benchmark from 'benny'
2 import { WorkerChoiceStrategies } from '../../lib/index.mjs'
3 import { PoolTypes, WorkerFunctions, WorkerTypes } from '../benchmarks-types.js'
4 import { buildPool, runTest } from '../benchmarks-utils.js'
7 const taskExecutions = 1
9 function: WorkerFunctions.jsonIntegerSerialization,
12 const tasksQueuePoolOption = { enableTasksQueue: true }
13 const workerChoiceStrategyRoundRobinPoolOption = {
14 workerChoiceStrategy: WorkerChoiceStrategies.ROUND_ROBIN
16 const workerChoiceStrategyLeastUsedPoolOption = {
17 workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED
19 const workerChoiceStrategyLeastBusyPoolOption = {
20 workerChoiceStrategy: WorkerChoiceStrategies.LEAST_BUSY
22 const workerChoiceStrategyWeightedRoundRobinPoolOption = {
23 workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
25 const workerChoiceStrategyFairSharePoolOption = {
26 workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE
29 const fixedThreadPoolRoundRobin = buildPool(
33 workerChoiceStrategyRoundRobinPoolOption
36 const fixedThreadPoolRoundRobinTasksQueue = buildPool(
40 { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
43 const fixedThreadPoolLeastUsed = buildPool(
47 workerChoiceStrategyLeastUsedPoolOption
50 const fixedThreadPoolLeastBusy = buildPool(
54 workerChoiceStrategyLeastBusyPoolOption
57 const fixedThreadPoolWeightedRoundRobin = buildPool(
61 workerChoiceStrategyWeightedRoundRobinPoolOption
64 const fixedThreadPoolFairShare = buildPool(
68 workerChoiceStrategyFairSharePoolOption
71 const fixedThreadPoolFairShareTasksQueue = buildPool(
75 { ...workerChoiceStrategyFairSharePoolOption, ...tasksQueuePoolOption }
78 const dynamicThreadPoolRoundRobin = buildPool(
82 workerChoiceStrategyRoundRobinPoolOption
85 const dynamicThreadPoolLeastUsed = buildPool(
89 workerChoiceStrategyLeastUsedPoolOption
92 const dynamicThreadPoolLeastBusy = buildPool(
96 workerChoiceStrategyLeastBusyPoolOption
99 const dynamicThreadPoolWeightedRoundRobin = buildPool(
103 workerChoiceStrategyWeightedRoundRobinPoolOption
106 const dynamicThreadPoolFairShare = buildPool(
110 workerChoiceStrategyFairSharePoolOption
113 const fixedClusterPoolRoundRobin = buildPool(
117 workerChoiceStrategyRoundRobinPoolOption
120 const fixedClusterPoolRoundRobinTasksQueue = buildPool(
124 { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
127 const fixedClusterPoolLeastUsed = buildPool(
131 workerChoiceStrategyLeastUsedPoolOption
134 const fixedClusterPoolLeastBusy = buildPool(
138 workerChoiceStrategyLeastBusyPoolOption
141 const fixedClusterPoolWeightedRoundRobin = buildPool(
145 workerChoiceStrategyWeightedRoundRobinPoolOption
148 const fixedClusterPoolFairShare = buildPool(
152 workerChoiceStrategyFairSharePoolOption
155 const fixedClusterPoolFairShareTaskQueue = buildPool(
159 { ...workerChoiceStrategyFairSharePoolOption, ...tasksQueuePoolOption }
162 const dynamicClusterPoolRoundRobin = buildPool(
166 workerChoiceStrategyRoundRobinPoolOption
169 const dynamicClusterPoolLeastUsed = buildPool(
173 workerChoiceStrategyLeastUsedPoolOption
176 const dynamicClusterPoolLeastBusy = buildPool(
180 workerChoiceStrategyLeastBusyPoolOption
183 const dynamicClusterPoolWeightedRoundRobin = buildPool(
187 workerChoiceStrategyWeightedRoundRobinPoolOption
190 const dynamicClusterPoolFairShare = buildPool(
194 workerChoiceStrategyFairSharePoolOption
197 const resultsFile = 'poolifier'
198 const resultsFolder = 'benchmarks/internal/results'
202 Benchmark.add('Fixed:ThreadPool:RoundRobin', async () => {
203 await runTest(fixedThreadPoolRoundRobin, {
209 'Fixed:ThreadPool:RoundRobin:{ enableTasksQueue: true }',
211 await runTest(fixedThreadPoolRoundRobinTasksQueue, {
217 Benchmark.add('Fixed:ThreadPool:LeastUsed', async () => {
218 await runTest(fixedThreadPoolLeastUsed, {
223 Benchmark.add('Fixed:ThreadPool:LeastBusy', async () => {
224 await runTest(fixedThreadPoolLeastBusy, {
229 Benchmark.add('Fixed:ThreadPool:WeightedRoundRobin', async () => {
230 await runTest(fixedThreadPoolWeightedRoundRobin, {
235 Benchmark.add('Fixed:ThreadPool:FairShare', async () => {
236 await runTest(fixedThreadPoolFairShare, {
242 'Fixed:ThreadPool:FairShare:{ enableTasksQueue: true }',
244 await runTest(fixedThreadPoolFairShareTasksQueue, {
250 Benchmark.add('Dynamic:ThreadPool:RoundRobin', async () => {
251 await runTest(dynamicThreadPoolRoundRobin, {
256 Benchmark.add('Dynamic:ThreadPool:LeastUsed', async () => {
257 await runTest(dynamicThreadPoolLeastUsed, {
262 Benchmark.add('Dynamic:ThreadPool:LeastBusy', async () => {
263 await runTest(dynamicThreadPoolLeastBusy, {
268 Benchmark.add('Dynamic:ThreadPool:WeightedRoundRobin', async () => {
269 await runTest(dynamicThreadPoolWeightedRoundRobin, {
274 Benchmark.add('Dynamic:ThreadPool:FairShare', async () => {
275 await runTest(dynamicThreadPoolFairShare, {
280 Benchmark.add('Fixed:ClusterPool:RoundRobin', async () => {
281 await runTest(fixedClusterPoolRoundRobin, {
287 'Fixed:ClusterPool:RoundRobin:{ enableTasksQueue: true }',
289 await runTest(fixedClusterPoolRoundRobinTasksQueue, {
295 Benchmark.add('Fixed:ClusterPool:LeastUsed', async () => {
296 await runTest(fixedClusterPoolLeastUsed, {
301 Benchmark.add('Fixed:ClusterPool:LeastBusy', async () => {
302 await runTest(fixedClusterPoolLeastBusy, {
307 Benchmark.add('Fixed:ClusterPool:WeightedRoundRobin', async () => {
308 await runTest(fixedClusterPoolWeightedRoundRobin, {
313 Benchmark.add('Fixed:ClusterPool:FairShare', async () => {
314 await runTest(fixedClusterPoolFairShare, {
320 'Fixed:ClusterPool:FairShare:{ enableTasksQueue: true }',
322 await runTest(fixedClusterPoolFairShareTaskQueue, {
328 Benchmark.add('Dynamic:ClusterPool:RoundRobin', async () => {
329 await runTest(dynamicClusterPoolRoundRobin, {
334 Benchmark.add('Dynamic:ClusterPool:LeastUsed', async () => {
335 await runTest(dynamicClusterPoolLeastUsed, {
340 Benchmark.add('Dynamic:ClusterPool:LeastBusy', async () => {
341 await runTest(dynamicClusterPoolLeastBusy, {
346 Benchmark.add('Dynamic:ClusterPool:WeightedRoundRobin', async () => {
347 await runTest(dynamicClusterPoolWeightedRoundRobin, {
352 Benchmark.add('Dynamic:ClusterPool:FairShare', async () => {
353 await runTest(dynamicClusterPoolFairShare, {
359 Benchmark.complete(),
362 folder: resultsFolder,
368 folder: resultsFolder,
369 format: 'chart.html',
374 folder: resultsFolder,
375 format: 'table.html',
380 // eslint-disable-next-line n/no-process-exit
381 return process.exit()
383 .catch(err => console.error(err))