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