chore: v2.6.6
[poolifier.git] / benchmarks / internal / bench.mjs
CommitLineData
8a970421
JB
1import Benchmark from 'benny'
2import { WorkerChoiceStrategies } from '../../lib/index.mjs'
8f810074
JB
3import {
4 PoolTypes,
5 WorkerFunctions,
6 WorkerTypes
7} from '../benchmarks-types.mjs'
8import { buildPool, runTest } from '../benchmarks-utils.mjs'
cdace0e5
JB
9
10const poolSize = 30
11const taskExecutions = 1
12const workerData = {
13 function: WorkerFunctions.jsonIntegerSerialization,
14 taskSize: 1000
15}
16const tasksQueuePoolOption = { enableTasksQueue: true }
17const workerChoiceStrategyRoundRobinPoolOption = {
18 workerChoiceStrategy: WorkerChoiceStrategies.ROUND_ROBIN
19}
e4543b14
JB
20const workerChoiceStrategyLeastUsedPoolOption = {
21 workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED
cdace0e5 22}
e4543b14
JB
23const workerChoiceStrategyLeastBusyPoolOption = {
24 workerChoiceStrategy: WorkerChoiceStrategies.LEAST_BUSY
cdace0e5
JB
25}
26const workerChoiceStrategyWeightedRoundRobinPoolOption = {
27 workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
28}
29const workerChoiceStrategyFairSharePoolOption = {
30 workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE
31}
32
33const fixedThreadPoolRoundRobin = buildPool(
bb615bd0
JB
34 WorkerTypes.thread,
35 PoolTypes.fixed,
cdace0e5 36 poolSize,
cdace0e5
JB
37 workerChoiceStrategyRoundRobinPoolOption
38)
39
40const fixedThreadPoolRoundRobinTasksQueue = buildPool(
bb615bd0
JB
41 WorkerTypes.thread,
42 PoolTypes.fixed,
cdace0e5 43 poolSize,
cdace0e5
JB
44 { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
45)
46
e4543b14 47const fixedThreadPoolLeastUsed = buildPool(
bb615bd0
JB
48 WorkerTypes.thread,
49 PoolTypes.fixed,
cdace0e5 50 poolSize,
e4543b14 51 workerChoiceStrategyLeastUsedPoolOption
cdace0e5
JB
52)
53
e4543b14 54const fixedThreadPoolLeastBusy = buildPool(
bb615bd0
JB
55 WorkerTypes.thread,
56 PoolTypes.fixed,
cdace0e5 57 poolSize,
e4543b14 58 workerChoiceStrategyLeastBusyPoolOption
cdace0e5
JB
59)
60
61const fixedThreadPoolWeightedRoundRobin = buildPool(
bb615bd0
JB
62 WorkerTypes.thread,
63 PoolTypes.fixed,
cdace0e5 64 poolSize,
cdace0e5
JB
65 workerChoiceStrategyWeightedRoundRobinPoolOption
66)
67
68const fixedThreadPoolFairShare = buildPool(
bb615bd0
JB
69 WorkerTypes.thread,
70 PoolTypes.fixed,
cdace0e5 71 poolSize,
cdace0e5
JB
72 workerChoiceStrategyFairSharePoolOption
73)
74
d9f14be6 75const fixedThreadPoolFairShareTasksQueue = buildPool(
bb615bd0
JB
76 WorkerTypes.thread,
77 PoolTypes.fixed,
d9f14be6
JB
78 poolSize,
79 { ...workerChoiceStrategyFairSharePoolOption, ...tasksQueuePoolOption }
80)
81
cdace0e5 82const dynamicThreadPoolRoundRobin = buildPool(
bb615bd0
JB
83 WorkerTypes.thread,
84 PoolTypes.dynamic,
cdace0e5 85 poolSize,
cdace0e5
JB
86 workerChoiceStrategyRoundRobinPoolOption
87)
88
e4543b14 89const dynamicThreadPoolLeastUsed = buildPool(
bb615bd0
JB
90 WorkerTypes.thread,
91 PoolTypes.dynamic,
cdace0e5 92 poolSize,
e4543b14 93 workerChoiceStrategyLeastUsedPoolOption
cdace0e5
JB
94)
95
e4543b14 96const dynamicThreadPoolLeastBusy = buildPool(
bb615bd0
JB
97 WorkerTypes.thread,
98 PoolTypes.dynamic,
cdace0e5 99 poolSize,
e4543b14 100 workerChoiceStrategyLeastBusyPoolOption
cdace0e5
JB
101)
102
103const dynamicThreadPoolWeightedRoundRobin = buildPool(
bb615bd0
JB
104 WorkerTypes.thread,
105 PoolTypes.dynamic,
cdace0e5 106 poolSize,
cdace0e5
JB
107 workerChoiceStrategyWeightedRoundRobinPoolOption
108)
109
110const dynamicThreadPoolFairShare = buildPool(
bb615bd0
JB
111 WorkerTypes.thread,
112 PoolTypes.dynamic,
cdace0e5 113 poolSize,
cdace0e5
JB
114 workerChoiceStrategyFairSharePoolOption
115)
116
117const fixedClusterPoolRoundRobin = buildPool(
bb615bd0
JB
118 WorkerTypes.cluster,
119 PoolTypes.fixed,
cdace0e5 120 poolSize,
cdace0e5
JB
121 workerChoiceStrategyRoundRobinPoolOption
122)
123
124const fixedClusterPoolRoundRobinTasksQueue = buildPool(
bb615bd0
JB
125 WorkerTypes.cluster,
126 PoolTypes.fixed,
cdace0e5 127 poolSize,
cdace0e5
JB
128 { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
129)
130
e4543b14 131const fixedClusterPoolLeastUsed = buildPool(
bb615bd0
JB
132 WorkerTypes.cluster,
133 PoolTypes.fixed,
cdace0e5 134 poolSize,
e4543b14 135 workerChoiceStrategyLeastUsedPoolOption
cdace0e5
JB
136)
137
e4543b14 138const fixedClusterPoolLeastBusy = buildPool(
bb615bd0
JB
139 WorkerTypes.cluster,
140 PoolTypes.fixed,
cdace0e5 141 poolSize,
e4543b14 142 workerChoiceStrategyLeastBusyPoolOption
cdace0e5
JB
143)
144
145const fixedClusterPoolWeightedRoundRobin = buildPool(
bb615bd0
JB
146 WorkerTypes.cluster,
147 PoolTypes.fixed,
cdace0e5 148 poolSize,
cdace0e5
JB
149 workerChoiceStrategyWeightedRoundRobinPoolOption
150)
151
152const fixedClusterPoolFairShare = buildPool(
bb615bd0
JB
153 WorkerTypes.cluster,
154 PoolTypes.fixed,
cdace0e5 155 poolSize,
cdace0e5
JB
156 workerChoiceStrategyFairSharePoolOption
157)
158
d9f14be6 159const fixedClusterPoolFairShareTaskQueue = buildPool(
bb615bd0
JB
160 WorkerTypes.cluster,
161 PoolTypes.fixed,
d9f14be6
JB
162 poolSize,
163 { ...workerChoiceStrategyFairSharePoolOption, ...tasksQueuePoolOption }
164)
165
cdace0e5 166const dynamicClusterPoolRoundRobin = buildPool(
bb615bd0
JB
167 WorkerTypes.cluster,
168 PoolTypes.dynamic,
cdace0e5 169 poolSize,
cdace0e5
JB
170 workerChoiceStrategyRoundRobinPoolOption
171)
172
e4543b14 173const dynamicClusterPoolLeastUsed = buildPool(
bb615bd0
JB
174 WorkerTypes.cluster,
175 PoolTypes.dynamic,
cdace0e5 176 poolSize,
e4543b14 177 workerChoiceStrategyLeastUsedPoolOption
cdace0e5
JB
178)
179
e4543b14 180const dynamicClusterPoolLeastBusy = buildPool(
bb615bd0
JB
181 WorkerTypes.cluster,
182 PoolTypes.dynamic,
cdace0e5 183 poolSize,
e4543b14 184 workerChoiceStrategyLeastBusyPoolOption
cdace0e5
JB
185)
186
187const dynamicClusterPoolWeightedRoundRobin = buildPool(
bb615bd0
JB
188 WorkerTypes.cluster,
189 PoolTypes.dynamic,
cdace0e5 190 poolSize,
cdace0e5
JB
191 workerChoiceStrategyWeightedRoundRobinPoolOption
192)
193
194const dynamicClusterPoolFairShare = buildPool(
bb615bd0
JB
195 WorkerTypes.cluster,
196 PoolTypes.dynamic,
cdace0e5 197 poolSize,
cdace0e5
JB
198 workerChoiceStrategyFairSharePoolOption
199)
325f50bc 200
ca6c7d70
JB
201const resultsFile = 'poolifier'
202const resultsFolder = 'benchmarks/internal/results'
57df5469 203
ca6c7d70
JB
204Benchmark.suite(
205 'Poolifier',
cdace0e5
JB
206 Benchmark.add('Fixed:ThreadPool:RoundRobin', async () => {
207 await runTest(fixedThreadPoolRoundRobin, {
208 taskExecutions,
209 workerData
210 })
ca6c7d70 211 }),
cdace0e5
JB
212 Benchmark.add(
213 'Fixed:ThreadPool:RoundRobin:{ enableTasksQueue: true }',
214 async () => {
215 await runTest(fixedThreadPoolRoundRobinTasksQueue, {
216 taskExecutions,
217 workerData
218 })
219 }
220 ),
e4543b14
JB
221 Benchmark.add('Fixed:ThreadPool:LeastUsed', async () => {
222 await runTest(fixedThreadPoolLeastUsed, {
cdace0e5
JB
223 taskExecutions,
224 workerData
225 })
ca6c7d70 226 }),
e4543b14
JB
227 Benchmark.add('Fixed:ThreadPool:LeastBusy', async () => {
228 await runTest(fixedThreadPoolLeastBusy, {
cdace0e5
JB
229 taskExecutions,
230 workerData
231 })
d4abc60a 232 }),
cdace0e5
JB
233 Benchmark.add('Fixed:ThreadPool:WeightedRoundRobin', async () => {
234 await runTest(fixedThreadPoolWeightedRoundRobin, {
235 taskExecutions,
236 workerData
237 })
ca6c7d70 238 }),
cdace0e5
JB
239 Benchmark.add('Fixed:ThreadPool:FairShare', async () => {
240 await runTest(fixedThreadPoolFairShare, {
241 taskExecutions,
242 workerData
243 })
ca6c7d70 244 }),
d9f14be6
JB
245 Benchmark.add(
246 'Fixed:ThreadPool:FairShare:{ enableTasksQueue: true }',
247 async () => {
248 await runTest(fixedThreadPoolFairShareTasksQueue, {
249 taskExecutions,
250 workerData
251 })
252 }
253 ),
cdace0e5
JB
254 Benchmark.add('Dynamic:ThreadPool:RoundRobin', async () => {
255 await runTest(dynamicThreadPoolRoundRobin, {
256 taskExecutions,
257 workerData
258 })
ca6c7d70 259 }),
e4543b14
JB
260 Benchmark.add('Dynamic:ThreadPool:LeastUsed', async () => {
261 await runTest(dynamicThreadPoolLeastUsed, {
cdace0e5
JB
262 taskExecutions,
263 workerData
264 })
ca6c7d70 265 }),
e4543b14
JB
266 Benchmark.add('Dynamic:ThreadPool:LeastBusy', async () => {
267 await runTest(dynamicThreadPoolLeastBusy, {
cdace0e5
JB
268 taskExecutions,
269 workerData
270 })
d4abc60a 271 }),
cdace0e5
JB
272 Benchmark.add('Dynamic:ThreadPool:WeightedRoundRobin', async () => {
273 await runTest(dynamicThreadPoolWeightedRoundRobin, {
274 taskExecutions,
275 workerData
276 })
ca6c7d70 277 }),
cdace0e5
JB
278 Benchmark.add('Dynamic:ThreadPool:FairShare', async () => {
279 await runTest(dynamicThreadPoolFairShare, {
280 taskExecutions,
281 workerData
282 })
ca6c7d70 283 }),
cdace0e5
JB
284 Benchmark.add('Fixed:ClusterPool:RoundRobin', async () => {
285 await runTest(fixedClusterPoolRoundRobin, {
286 taskExecutions,
287 workerData
288 })
ca6c7d70 289 }),
cdace0e5
JB
290 Benchmark.add(
291 'Fixed:ClusterPool:RoundRobin:{ enableTasksQueue: true }',
292 async () => {
293 await runTest(fixedClusterPoolRoundRobinTasksQueue, {
294 taskExecutions,
295 workerData
296 })
297 }
298 ),
e4543b14
JB
299 Benchmark.add('Fixed:ClusterPool:LeastUsed', async () => {
300 await runTest(fixedClusterPoolLeastUsed, {
cdace0e5
JB
301 taskExecutions,
302 workerData
303 })
869b1a45 304 }),
e4543b14
JB
305 Benchmark.add('Fixed:ClusterPool:LeastBusy', async () => {
306 await runTest(fixedClusterPoolLeastBusy, {
cdace0e5
JB
307 taskExecutions,
308 workerData
309 })
ca6c7d70 310 }),
cdace0e5
JB
311 Benchmark.add('Fixed:ClusterPool:WeightedRoundRobin', async () => {
312 await runTest(fixedClusterPoolWeightedRoundRobin, {
313 taskExecutions,
314 workerData
315 })
d4abc60a 316 }),
cdace0e5
JB
317 Benchmark.add('Fixed:ClusterPool:FairShare', async () => {
318 await runTest(fixedClusterPoolFairShare, {
319 taskExecutions,
320 workerData
321 })
ca6c7d70 322 }),
d9f14be6
JB
323 Benchmark.add(
324 'Fixed:ClusterPool:FairShare:{ enableTasksQueue: true }',
325 async () => {
326 await runTest(fixedClusterPoolFairShareTaskQueue, {
327 taskExecutions,
328 workerData
329 })
330 }
331 ),
cdace0e5
JB
332 Benchmark.add('Dynamic:ClusterPool:RoundRobin', async () => {
333 await runTest(dynamicClusterPoolRoundRobin, {
334 taskExecutions,
335 workerData
336 })
ca6c7d70 337 }),
e4543b14
JB
338 Benchmark.add('Dynamic:ClusterPool:LeastUsed', async () => {
339 await runTest(dynamicClusterPoolLeastUsed, {
cdace0e5
JB
340 taskExecutions,
341 workerData
342 })
ca6c7d70 343 }),
e4543b14
JB
344 Benchmark.add('Dynamic:ClusterPool:LeastBusy', async () => {
345 await runTest(dynamicClusterPoolLeastBusy, {
cdace0e5
JB
346 taskExecutions,
347 workerData
348 })
ca6c7d70 349 }),
cdace0e5
JB
350 Benchmark.add('Dynamic:ClusterPool:WeightedRoundRobin', async () => {
351 await runTest(dynamicClusterPoolWeightedRoundRobin, {
352 taskExecutions,
353 workerData
354 })
d4abc60a 355 }),
cdace0e5
JB
356 Benchmark.add('Dynamic:ClusterPool:FairShare', async () => {
357 await runTest(dynamicClusterPoolFairShare, {
358 taskExecutions,
359 workerData
360 })
ca6c7d70
JB
361 }),
362 Benchmark.cycle(),
363 Benchmark.complete(),
364 Benchmark.save({
365 file: resultsFile,
366 folder: resultsFolder,
367 format: 'json',
368 details: true
369 }),
370 Benchmark.save({
371 file: resultsFile,
372 folder: resultsFolder,
373 format: 'chart.html',
374 details: true
375 }),
376 Benchmark.save({
377 file: resultsFile,
378 folder: resultsFolder,
379 format: 'table.html',
380 details: true
381 })
382)
18cac485
JB
383 .then(() => {
384 // eslint-disable-next-line n/no-process-exit
385 return process.exit()
386 })
387 .catch(err => console.error(err))