docs: add changelog entry for IWRR worker choice strategy
[poolifier.git] / benchmarks / internal / bench.js
CommitLineData
ca6c7d70 1const Benchmark = require('benny')
cdace0e5 2const { WorkerChoiceStrategies } = require('../../lib')
ff5e76e1 3const {
cdace0e5
JB
4 PoolTypes,
5 WorkerFunctions,
6 WorkerTypes
7} = require('../benchmarks-types')
8const { buildPool, runTest } = require('../benchmarks-utils')
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(
1f29c16f 34 WorkerTypes.THREAD,
cdace0e5
JB
35 PoolTypes.FIXED,
36 poolSize,
cdace0e5
JB
37 workerChoiceStrategyRoundRobinPoolOption
38)
39
40const fixedThreadPoolRoundRobinTasksQueue = buildPool(
1f29c16f 41 WorkerTypes.THREAD,
cdace0e5
JB
42 PoolTypes.FIXED,
43 poolSize,
cdace0e5
JB
44 { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
45)
46
e4543b14 47const fixedThreadPoolLeastUsed = buildPool(
1f29c16f 48 WorkerTypes.THREAD,
cdace0e5
JB
49 PoolTypes.FIXED,
50 poolSize,
e4543b14 51 workerChoiceStrategyLeastUsedPoolOption
cdace0e5
JB
52)
53
e4543b14 54const fixedThreadPoolLeastBusy = buildPool(
1f29c16f 55 WorkerTypes.THREAD,
cdace0e5
JB
56 PoolTypes.FIXED,
57 poolSize,
e4543b14 58 workerChoiceStrategyLeastBusyPoolOption
cdace0e5
JB
59)
60
61const fixedThreadPoolWeightedRoundRobin = buildPool(
1f29c16f 62 WorkerTypes.THREAD,
cdace0e5
JB
63 PoolTypes.FIXED,
64 poolSize,
cdace0e5
JB
65 workerChoiceStrategyWeightedRoundRobinPoolOption
66)
67
68const fixedThreadPoolFairShare = buildPool(
1f29c16f 69 WorkerTypes.THREAD,
cdace0e5
JB
70 PoolTypes.FIXED,
71 poolSize,
cdace0e5
JB
72 workerChoiceStrategyFairSharePoolOption
73)
74
d9f14be6
JB
75const fixedThreadPoolFairShareTasksQueue = buildPool(
76 WorkerTypes.THREAD,
77 PoolTypes.FIXED,
78 poolSize,
79 { ...workerChoiceStrategyFairSharePoolOption, ...tasksQueuePoolOption }
80)
81
cdace0e5 82const dynamicThreadPoolRoundRobin = buildPool(
1f29c16f 83 WorkerTypes.THREAD,
cdace0e5
JB
84 PoolTypes.DYNAMIC,
85 poolSize,
cdace0e5
JB
86 workerChoiceStrategyRoundRobinPoolOption
87)
88
e4543b14 89const dynamicThreadPoolLeastUsed = buildPool(
1f29c16f 90 WorkerTypes.THREAD,
cdace0e5
JB
91 PoolTypes.DYNAMIC,
92 poolSize,
e4543b14 93 workerChoiceStrategyLeastUsedPoolOption
cdace0e5
JB
94)
95
e4543b14 96const dynamicThreadPoolLeastBusy = buildPool(
1f29c16f 97 WorkerTypes.THREAD,
cdace0e5
JB
98 PoolTypes.DYNAMIC,
99 poolSize,
e4543b14 100 workerChoiceStrategyLeastBusyPoolOption
cdace0e5
JB
101)
102
103const dynamicThreadPoolWeightedRoundRobin = buildPool(
1f29c16f 104 WorkerTypes.THREAD,
cdace0e5
JB
105 PoolTypes.DYNAMIC,
106 poolSize,
cdace0e5
JB
107 workerChoiceStrategyWeightedRoundRobinPoolOption
108)
109
110const dynamicThreadPoolFairShare = buildPool(
1f29c16f 111 WorkerTypes.THREAD,
cdace0e5
JB
112 PoolTypes.DYNAMIC,
113 poolSize,
cdace0e5
JB
114 workerChoiceStrategyFairSharePoolOption
115)
116
117const fixedClusterPoolRoundRobin = buildPool(
1f29c16f 118 WorkerTypes.CLUSTER,
cdace0e5
JB
119 PoolTypes.FIXED,
120 poolSize,
cdace0e5
JB
121 workerChoiceStrategyRoundRobinPoolOption
122)
123
124const fixedClusterPoolRoundRobinTasksQueue = buildPool(
1f29c16f 125 WorkerTypes.CLUSTER,
cdace0e5
JB
126 PoolTypes.FIXED,
127 poolSize,
cdace0e5
JB
128 { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
129)
130
e4543b14 131const fixedClusterPoolLeastUsed = buildPool(
1f29c16f 132 WorkerTypes.CLUSTER,
cdace0e5
JB
133 PoolTypes.FIXED,
134 poolSize,
e4543b14 135 workerChoiceStrategyLeastUsedPoolOption
cdace0e5
JB
136)
137
e4543b14 138const fixedClusterPoolLeastBusy = buildPool(
1f29c16f 139 WorkerTypes.CLUSTER,
cdace0e5
JB
140 PoolTypes.FIXED,
141 poolSize,
e4543b14 142 workerChoiceStrategyLeastBusyPoolOption
cdace0e5
JB
143)
144
145const fixedClusterPoolWeightedRoundRobin = buildPool(
1f29c16f 146 WorkerTypes.CLUSTER,
cdace0e5
JB
147 PoolTypes.FIXED,
148 poolSize,
cdace0e5
JB
149 workerChoiceStrategyWeightedRoundRobinPoolOption
150)
151
152const fixedClusterPoolFairShare = buildPool(
1f29c16f 153 WorkerTypes.CLUSTER,
cdace0e5
JB
154 PoolTypes.FIXED,
155 poolSize,
cdace0e5
JB
156 workerChoiceStrategyFairSharePoolOption
157)
158
d9f14be6
JB
159const fixedClusterPoolFairShareTaskQueue = buildPool(
160 WorkerTypes.CLUSTER,
161 PoolTypes.FIXED,
162 poolSize,
163 { ...workerChoiceStrategyFairSharePoolOption, ...tasksQueuePoolOption }
164)
165
cdace0e5 166const dynamicClusterPoolRoundRobin = buildPool(
1f29c16f 167 WorkerTypes.CLUSTER,
cdace0e5
JB
168 PoolTypes.DYNAMIC,
169 poolSize,
cdace0e5
JB
170 workerChoiceStrategyRoundRobinPoolOption
171)
172
e4543b14 173const dynamicClusterPoolLeastUsed = buildPool(
1f29c16f 174 WorkerTypes.CLUSTER,
cdace0e5
JB
175 PoolTypes.DYNAMIC,
176 poolSize,
e4543b14 177 workerChoiceStrategyLeastUsedPoolOption
cdace0e5
JB
178)
179
e4543b14 180const dynamicClusterPoolLeastBusy = buildPool(
1f29c16f 181 WorkerTypes.CLUSTER,
cdace0e5
JB
182 PoolTypes.DYNAMIC,
183 poolSize,
e4543b14 184 workerChoiceStrategyLeastBusyPoolOption
cdace0e5
JB
185)
186
187const dynamicClusterPoolWeightedRoundRobin = buildPool(
1f29c16f 188 WorkerTypes.CLUSTER,
cdace0e5
JB
189 PoolTypes.DYNAMIC,
190 poolSize,
cdace0e5
JB
191 workerChoiceStrategyWeightedRoundRobinPoolOption
192)
193
194const dynamicClusterPoolFairShare = buildPool(
1f29c16f 195 WorkerTypes.CLUSTER,
cdace0e5
JB
196 PoolTypes.DYNAMIC,
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))