1 import Benchmark from 'benny'
3 WorkerChoiceStrategies,
5 } from '../../lib/index.mjs'
10 } from '../benchmarks-types.mjs'
11 import { buildPool, runTest } from '../benchmarks-utils.mjs'
13 const poolSize = availableParallelism()
14 const taskExecutions = 1
16 function: WorkerFunctions.jsonIntegerSerialization,
19 const tasksQueuePoolOption = { enableTasksQueue: true }
20 const workerChoiceStrategyRoundRobinPoolOption = {
21 workerChoiceStrategy: WorkerChoiceStrategies.ROUND_ROBIN
23 const workerChoiceStrategyLeastUsedPoolOption = {
24 workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED
26 const workerChoiceStrategyLeastBusyPoolOption = {
27 workerChoiceStrategy: WorkerChoiceStrategies.LEAST_BUSY
29 const workerChoiceStrategyWeightedRoundRobinPoolOption = {
30 workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
32 const workerChoiceStrategyFairSharePoolOption = {
33 workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE
36 const fixedThreadPoolRoundRobin = buildPool(
40 workerChoiceStrategyRoundRobinPoolOption
43 const fixedThreadPoolRoundRobinTasksQueue = buildPool(
47 { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
50 const fixedThreadPoolLeastUsed = buildPool(
54 workerChoiceStrategyLeastUsedPoolOption
57 const fixedThreadPoolLeastBusy = buildPool(
61 workerChoiceStrategyLeastBusyPoolOption
64 const fixedThreadPoolWeightedRoundRobin = buildPool(
68 workerChoiceStrategyWeightedRoundRobinPoolOption
71 const fixedThreadPoolFairShare = buildPool(
75 workerChoiceStrategyFairSharePoolOption
78 const fixedThreadPoolFairShareTasksQueue = buildPool(
82 { ...workerChoiceStrategyFairSharePoolOption, ...tasksQueuePoolOption }
85 const dynamicThreadPoolRoundRobin = buildPool(
89 workerChoiceStrategyRoundRobinPoolOption
92 const dynamicThreadPoolLeastUsed = buildPool(
96 workerChoiceStrategyLeastUsedPoolOption
99 const dynamicThreadPoolLeastBusy = buildPool(
103 workerChoiceStrategyLeastBusyPoolOption
106 const dynamicThreadPoolWeightedRoundRobin = buildPool(
110 workerChoiceStrategyWeightedRoundRobinPoolOption
113 const dynamicThreadPoolFairShare = buildPool(
117 workerChoiceStrategyFairSharePoolOption
120 const fixedClusterPoolRoundRobin = buildPool(
124 workerChoiceStrategyRoundRobinPoolOption
127 const fixedClusterPoolRoundRobinTasksQueue = buildPool(
131 { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
134 const fixedClusterPoolLeastUsed = buildPool(
138 workerChoiceStrategyLeastUsedPoolOption
141 const fixedClusterPoolLeastBusy = buildPool(
145 workerChoiceStrategyLeastBusyPoolOption
148 const fixedClusterPoolWeightedRoundRobin = buildPool(
152 workerChoiceStrategyWeightedRoundRobinPoolOption
155 const fixedClusterPoolFairShare = buildPool(
159 workerChoiceStrategyFairSharePoolOption
162 const fixedClusterPoolFairShareTaskQueue = buildPool(
166 { ...workerChoiceStrategyFairSharePoolOption, ...tasksQueuePoolOption }
169 const dynamicClusterPoolRoundRobin = buildPool(
173 workerChoiceStrategyRoundRobinPoolOption
176 const dynamicClusterPoolLeastUsed = buildPool(
180 workerChoiceStrategyLeastUsedPoolOption
183 const dynamicClusterPoolLeastBusy = buildPool(
187 workerChoiceStrategyLeastBusyPoolOption
190 const dynamicClusterPoolWeightedRoundRobin = buildPool(
194 workerChoiceStrategyWeightedRoundRobinPoolOption
197 const dynamicClusterPoolFairShare = buildPool(
201 workerChoiceStrategyFairSharePoolOption
204 const resultsFile = 'poolifier'
205 const resultsFolder = 'benchmarks/internal/results'
209 Benchmark.add('Fixed:ThreadPool:RoundRobin', async () => {
210 await runTest(fixedThreadPoolRoundRobin, {
216 'Fixed:ThreadPool:RoundRobin:{ enableTasksQueue: true }',
218 await runTest(fixedThreadPoolRoundRobinTasksQueue, {
224 Benchmark.add('Fixed:ThreadPool:LeastUsed', async () => {
225 await runTest(fixedThreadPoolLeastUsed, {
230 Benchmark.add('Fixed:ThreadPool:LeastBusy', async () => {
231 await runTest(fixedThreadPoolLeastBusy, {
236 Benchmark.add('Fixed:ThreadPool:WeightedRoundRobin', async () => {
237 await runTest(fixedThreadPoolWeightedRoundRobin, {
242 Benchmark.add('Fixed:ThreadPool:FairShare', async () => {
243 await runTest(fixedThreadPoolFairShare, {
249 'Fixed:ThreadPool:FairShare:{ enableTasksQueue: true }',
251 await runTest(fixedThreadPoolFairShareTasksQueue, {
257 Benchmark.add('Dynamic:ThreadPool:RoundRobin', async () => {
258 await runTest(dynamicThreadPoolRoundRobin, {
263 Benchmark.add('Dynamic:ThreadPool:LeastUsed', async () => {
264 await runTest(dynamicThreadPoolLeastUsed, {
269 Benchmark.add('Dynamic:ThreadPool:LeastBusy', async () => {
270 await runTest(dynamicThreadPoolLeastBusy, {
275 Benchmark.add('Dynamic:ThreadPool:WeightedRoundRobin', async () => {
276 await runTest(dynamicThreadPoolWeightedRoundRobin, {
281 Benchmark.add('Dynamic:ThreadPool:FairShare', async () => {
282 await runTest(dynamicThreadPoolFairShare, {
287 Benchmark.add('Fixed:ClusterPool:RoundRobin', async () => {
288 await runTest(fixedClusterPoolRoundRobin, {
294 'Fixed:ClusterPool:RoundRobin:{ enableTasksQueue: true }',
296 await runTest(fixedClusterPoolRoundRobinTasksQueue, {
302 Benchmark.add('Fixed:ClusterPool:LeastUsed', async () => {
303 await runTest(fixedClusterPoolLeastUsed, {
308 Benchmark.add('Fixed:ClusterPool:LeastBusy', async () => {
309 await runTest(fixedClusterPoolLeastBusy, {
314 Benchmark.add('Fixed:ClusterPool:WeightedRoundRobin', async () => {
315 await runTest(fixedClusterPoolWeightedRoundRobin, {
320 Benchmark.add('Fixed:ClusterPool:FairShare', async () => {
321 await runTest(fixedClusterPoolFairShare, {
327 'Fixed:ClusterPool:FairShare:{ enableTasksQueue: true }',
329 await runTest(fixedClusterPoolFairShareTaskQueue, {
335 Benchmark.add('Dynamic:ClusterPool:RoundRobin', async () => {
336 await runTest(dynamicClusterPoolRoundRobin, {
341 Benchmark.add('Dynamic:ClusterPool:LeastUsed', async () => {
342 await runTest(dynamicClusterPoolLeastUsed, {
347 Benchmark.add('Dynamic:ClusterPool:LeastBusy', async () => {
348 await runTest(dynamicClusterPoolLeastBusy, {
353 Benchmark.add('Dynamic:ClusterPool:WeightedRoundRobin', async () => {
354 await runTest(dynamicClusterPoolWeightedRoundRobin, {
359 Benchmark.add('Dynamic:ClusterPool:FairShare', async () => {
360 await runTest(dynamicClusterPoolFairShare, {
366 Benchmark.complete(),
369 folder: resultsFolder,
375 folder: resultsFolder,
376 format: 'chart.html',
381 folder: resultsFolder,
382 format: 'table.html',
387 // eslint-disable-next-line n/no-process-exit
388 return process.exit()
390 .catch(err => console.error(err))