Commit | Line | Data |
---|---|---|
ca6c7d70 | 1 | const Benchmark = require('benny') |
cdace0e5 | 2 | const { WorkerChoiceStrategies } = require('../../lib') |
ff5e76e1 | 3 | const { |
cdace0e5 JB |
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 workerChoiceStrategyLessUsedPoolOption = { | |
21 | workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED | |
22 | } | |
23 | const workerChoiceStrategyLessBusyPoolOption = { | |
24 | workerChoiceStrategy: WorkerChoiceStrategies.LESS_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( | |
1f29c16f | 34 | WorkerTypes.THREAD, |
cdace0e5 JB |
35 | PoolTypes.FIXED, |
36 | poolSize, | |
cdace0e5 JB |
37 | workerChoiceStrategyRoundRobinPoolOption |
38 | ) | |
39 | ||
40 | const fixedThreadPoolRoundRobinTasksQueue = buildPool( | |
1f29c16f | 41 | WorkerTypes.THREAD, |
cdace0e5 JB |
42 | PoolTypes.FIXED, |
43 | poolSize, | |
cdace0e5 JB |
44 | { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption } |
45 | ) | |
46 | ||
47 | const fixedThreadPoolLessUsed = buildPool( | |
1f29c16f | 48 | WorkerTypes.THREAD, |
cdace0e5 JB |
49 | PoolTypes.FIXED, |
50 | poolSize, | |
cdace0e5 JB |
51 | workerChoiceStrategyLessUsedPoolOption |
52 | ) | |
53 | ||
54 | const fixedThreadPoolLessBusy = buildPool( | |
1f29c16f | 55 | WorkerTypes.THREAD, |
cdace0e5 JB |
56 | PoolTypes.FIXED, |
57 | poolSize, | |
cdace0e5 JB |
58 | workerChoiceStrategyLessBusyPoolOption |
59 | ) | |
60 | ||
61 | const fixedThreadPoolWeightedRoundRobin = buildPool( | |
1f29c16f | 62 | WorkerTypes.THREAD, |
cdace0e5 JB |
63 | PoolTypes.FIXED, |
64 | poolSize, | |
cdace0e5 JB |
65 | workerChoiceStrategyWeightedRoundRobinPoolOption |
66 | ) | |
67 | ||
68 | const fixedThreadPoolFairShare = buildPool( | |
1f29c16f | 69 | WorkerTypes.THREAD, |
cdace0e5 JB |
70 | PoolTypes.FIXED, |
71 | poolSize, | |
cdace0e5 JB |
72 | workerChoiceStrategyFairSharePoolOption |
73 | ) | |
74 | ||
75 | const dynamicThreadPoolRoundRobin = buildPool( | |
1f29c16f | 76 | WorkerTypes.THREAD, |
cdace0e5 JB |
77 | PoolTypes.DYNAMIC, |
78 | poolSize, | |
cdace0e5 JB |
79 | workerChoiceStrategyRoundRobinPoolOption |
80 | ) | |
81 | ||
82 | const dynamicThreadPoolLessUsed = buildPool( | |
1f29c16f | 83 | WorkerTypes.THREAD, |
cdace0e5 JB |
84 | PoolTypes.DYNAMIC, |
85 | poolSize, | |
cdace0e5 JB |
86 | workerChoiceStrategyLessUsedPoolOption |
87 | ) | |
88 | ||
89 | const dynamicThreadPoolLessBusy = buildPool( | |
1f29c16f | 90 | WorkerTypes.THREAD, |
cdace0e5 JB |
91 | PoolTypes.DYNAMIC, |
92 | poolSize, | |
cdace0e5 JB |
93 | workerChoiceStrategyLessBusyPoolOption |
94 | ) | |
95 | ||
96 | const dynamicThreadPoolWeightedRoundRobin = buildPool( | |
1f29c16f | 97 | WorkerTypes.THREAD, |
cdace0e5 JB |
98 | PoolTypes.DYNAMIC, |
99 | poolSize, | |
cdace0e5 JB |
100 | workerChoiceStrategyWeightedRoundRobinPoolOption |
101 | ) | |
102 | ||
103 | const dynamicThreadPoolFairShare = buildPool( | |
1f29c16f | 104 | WorkerTypes.THREAD, |
cdace0e5 JB |
105 | PoolTypes.DYNAMIC, |
106 | poolSize, | |
cdace0e5 JB |
107 | workerChoiceStrategyFairSharePoolOption |
108 | ) | |
109 | ||
110 | const fixedClusterPoolRoundRobin = buildPool( | |
1f29c16f | 111 | WorkerTypes.CLUSTER, |
cdace0e5 JB |
112 | PoolTypes.FIXED, |
113 | poolSize, | |
cdace0e5 JB |
114 | workerChoiceStrategyRoundRobinPoolOption |
115 | ) | |
116 | ||
117 | const fixedClusterPoolRoundRobinTasksQueue = buildPool( | |
1f29c16f | 118 | WorkerTypes.CLUSTER, |
cdace0e5 JB |
119 | PoolTypes.FIXED, |
120 | poolSize, | |
cdace0e5 JB |
121 | { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption } |
122 | ) | |
123 | ||
124 | const fixedClusterPoolLessUsed = buildPool( | |
1f29c16f | 125 | WorkerTypes.CLUSTER, |
cdace0e5 JB |
126 | PoolTypes.FIXED, |
127 | poolSize, | |
cdace0e5 JB |
128 | workerChoiceStrategyLessUsedPoolOption |
129 | ) | |
130 | ||
131 | const fixedClusterPoolLessBusy = buildPool( | |
1f29c16f | 132 | WorkerTypes.CLUSTER, |
cdace0e5 JB |
133 | PoolTypes.FIXED, |
134 | poolSize, | |
cdace0e5 JB |
135 | workerChoiceStrategyLessBusyPoolOption |
136 | ) | |
137 | ||
138 | const fixedClusterPoolWeightedRoundRobin = buildPool( | |
1f29c16f | 139 | WorkerTypes.CLUSTER, |
cdace0e5 JB |
140 | PoolTypes.FIXED, |
141 | poolSize, | |
cdace0e5 JB |
142 | workerChoiceStrategyWeightedRoundRobinPoolOption |
143 | ) | |
144 | ||
145 | const fixedClusterPoolFairShare = buildPool( | |
1f29c16f | 146 | WorkerTypes.CLUSTER, |
cdace0e5 JB |
147 | PoolTypes.FIXED, |
148 | poolSize, | |
cdace0e5 JB |
149 | workerChoiceStrategyFairSharePoolOption |
150 | ) | |
151 | ||
152 | const dynamicClusterPoolRoundRobin = buildPool( | |
1f29c16f | 153 | WorkerTypes.CLUSTER, |
cdace0e5 JB |
154 | PoolTypes.DYNAMIC, |
155 | poolSize, | |
cdace0e5 JB |
156 | workerChoiceStrategyRoundRobinPoolOption |
157 | ) | |
158 | ||
159 | const dynamicClusterPoolLessUsed = buildPool( | |
1f29c16f | 160 | WorkerTypes.CLUSTER, |
cdace0e5 JB |
161 | PoolTypes.DYNAMIC, |
162 | poolSize, | |
cdace0e5 JB |
163 | workerChoiceStrategyLessUsedPoolOption |
164 | ) | |
165 | ||
166 | const dynamicClusterPoolLessBusy = buildPool( | |
1f29c16f | 167 | WorkerTypes.CLUSTER, |
cdace0e5 JB |
168 | PoolTypes.DYNAMIC, |
169 | poolSize, | |
cdace0e5 JB |
170 | workerChoiceStrategyLessBusyPoolOption |
171 | ) | |
172 | ||
173 | const dynamicClusterPoolWeightedRoundRobin = buildPool( | |
1f29c16f | 174 | WorkerTypes.CLUSTER, |
cdace0e5 JB |
175 | PoolTypes.DYNAMIC, |
176 | poolSize, | |
cdace0e5 JB |
177 | workerChoiceStrategyWeightedRoundRobinPoolOption |
178 | ) | |
179 | ||
180 | const dynamicClusterPoolFairShare = buildPool( | |
1f29c16f | 181 | WorkerTypes.CLUSTER, |
cdace0e5 JB |
182 | PoolTypes.DYNAMIC, |
183 | poolSize, | |
cdace0e5 JB |
184 | workerChoiceStrategyFairSharePoolOption |
185 | ) | |
325f50bc | 186 | |
ca6c7d70 JB |
187 | const resultsFile = 'poolifier' |
188 | const resultsFolder = 'benchmarks/internal/results' | |
57df5469 | 189 | |
ca6c7d70 JB |
190 | Benchmark.suite( |
191 | 'Poolifier', | |
cdace0e5 JB |
192 | Benchmark.add('Fixed:ThreadPool:RoundRobin', async () => { |
193 | await runTest(fixedThreadPoolRoundRobin, { | |
194 | taskExecutions, | |
195 | workerData | |
196 | }) | |
ca6c7d70 | 197 | }), |
cdace0e5 JB |
198 | Benchmark.add( |
199 | 'Fixed:ThreadPool:RoundRobin:{ enableTasksQueue: true }', | |
200 | async () => { | |
201 | await runTest(fixedThreadPoolRoundRobinTasksQueue, { | |
202 | taskExecutions, | |
203 | workerData | |
204 | }) | |
205 | } | |
206 | ), | |
207 | Benchmark.add('Fixed:ThreadPool:LessUsed', async () => { | |
208 | await runTest(fixedThreadPoolLessUsed, { | |
209 | taskExecutions, | |
210 | workerData | |
211 | }) | |
ca6c7d70 | 212 | }), |
cdace0e5 JB |
213 | Benchmark.add('Fixed:ThreadPool:LessBusy', async () => { |
214 | await runTest(fixedThreadPoolLessBusy, { | |
215 | taskExecutions, | |
216 | workerData | |
217 | }) | |
d4abc60a | 218 | }), |
cdace0e5 JB |
219 | Benchmark.add('Fixed:ThreadPool:WeightedRoundRobin', async () => { |
220 | await runTest(fixedThreadPoolWeightedRoundRobin, { | |
221 | taskExecutions, | |
222 | workerData | |
223 | }) | |
ca6c7d70 | 224 | }), |
cdace0e5 JB |
225 | Benchmark.add('Fixed:ThreadPool:FairShare', async () => { |
226 | await runTest(fixedThreadPoolFairShare, { | |
227 | taskExecutions, | |
228 | workerData | |
229 | }) | |
ca6c7d70 | 230 | }), |
cdace0e5 JB |
231 | Benchmark.add('Dynamic:ThreadPool:RoundRobin', async () => { |
232 | await runTest(dynamicThreadPoolRoundRobin, { | |
233 | taskExecutions, | |
234 | workerData | |
235 | }) | |
ca6c7d70 | 236 | }), |
cdace0e5 JB |
237 | Benchmark.add('Dynamic:ThreadPool:LessUsed', async () => { |
238 | await runTest(dynamicThreadPoolLessUsed, { | |
239 | taskExecutions, | |
240 | workerData | |
241 | }) | |
ca6c7d70 | 242 | }), |
cdace0e5 JB |
243 | Benchmark.add('Dynamic:ThreadPool:LessBusy', async () => { |
244 | await runTest(dynamicThreadPoolLessBusy, { | |
245 | taskExecutions, | |
246 | workerData | |
247 | }) | |
d4abc60a | 248 | }), |
cdace0e5 JB |
249 | Benchmark.add('Dynamic:ThreadPool:WeightedRoundRobin', async () => { |
250 | await runTest(dynamicThreadPoolWeightedRoundRobin, { | |
251 | taskExecutions, | |
252 | workerData | |
253 | }) | |
ca6c7d70 | 254 | }), |
cdace0e5 JB |
255 | Benchmark.add('Dynamic:ThreadPool:FairShare', async () => { |
256 | await runTest(dynamicThreadPoolFairShare, { | |
257 | taskExecutions, | |
258 | workerData | |
259 | }) | |
ca6c7d70 | 260 | }), |
cdace0e5 JB |
261 | Benchmark.add('Fixed:ClusterPool:RoundRobin', async () => { |
262 | await runTest(fixedClusterPoolRoundRobin, { | |
263 | taskExecutions, | |
264 | workerData | |
265 | }) | |
ca6c7d70 | 266 | }), |
cdace0e5 JB |
267 | Benchmark.add( |
268 | 'Fixed:ClusterPool:RoundRobin:{ enableTasksQueue: true }', | |
269 | async () => { | |
270 | await runTest(fixedClusterPoolRoundRobinTasksQueue, { | |
271 | taskExecutions, | |
272 | workerData | |
273 | }) | |
274 | } | |
275 | ), | |
276 | Benchmark.add('Fixed:ClusterPool:LessUsed', async () => { | |
277 | await runTest(fixedClusterPoolLessUsed, { | |
278 | taskExecutions, | |
279 | workerData | |
280 | }) | |
869b1a45 | 281 | }), |
cdace0e5 JB |
282 | Benchmark.add('Fixed:ClusterPool:LessBusy', async () => { |
283 | await runTest(fixedClusterPoolLessBusy, { | |
284 | taskExecutions, | |
285 | workerData | |
286 | }) | |
ca6c7d70 | 287 | }), |
cdace0e5 JB |
288 | Benchmark.add('Fixed:ClusterPool:WeightedRoundRobin', async () => { |
289 | await runTest(fixedClusterPoolWeightedRoundRobin, { | |
290 | taskExecutions, | |
291 | workerData | |
292 | }) | |
d4abc60a | 293 | }), |
cdace0e5 JB |
294 | Benchmark.add('Fixed:ClusterPool:FairShare', async () => { |
295 | await runTest(fixedClusterPoolFairShare, { | |
296 | taskExecutions, | |
297 | workerData | |
298 | }) | |
ca6c7d70 | 299 | }), |
cdace0e5 JB |
300 | Benchmark.add('Dynamic:ClusterPool:RoundRobin', async () => { |
301 | await runTest(dynamicClusterPoolRoundRobin, { | |
302 | taskExecutions, | |
303 | workerData | |
304 | }) | |
ca6c7d70 | 305 | }), |
cdace0e5 JB |
306 | Benchmark.add('Dynamic:ClusterPool:LessUsed', async () => { |
307 | await runTest(dynamicClusterPoolLessUsed, { | |
308 | taskExecutions, | |
309 | workerData | |
310 | }) | |
ca6c7d70 | 311 | }), |
cdace0e5 JB |
312 | Benchmark.add('Dynamic:ClusterPool:LessBusy', async () => { |
313 | await runTest(dynamicClusterPoolLessBusy, { | |
314 | taskExecutions, | |
315 | workerData | |
316 | }) | |
ca6c7d70 | 317 | }), |
cdace0e5 JB |
318 | Benchmark.add('Dynamic:ClusterPool:WeightedRoundRobin', async () => { |
319 | await runTest(dynamicClusterPoolWeightedRoundRobin, { | |
320 | taskExecutions, | |
321 | workerData | |
322 | }) | |
d4abc60a | 323 | }), |
cdace0e5 JB |
324 | Benchmark.add('Dynamic:ClusterPool:FairShare', async () => { |
325 | await runTest(dynamicClusterPoolFairShare, { | |
326 | taskExecutions, | |
327 | workerData | |
328 | }) | |
ca6c7d70 JB |
329 | }), |
330 | Benchmark.cycle(), | |
331 | Benchmark.complete(), | |
332 | Benchmark.save({ | |
333 | file: resultsFile, | |
334 | folder: resultsFolder, | |
335 | format: 'json', | |
336 | details: true | |
337 | }), | |
338 | Benchmark.save({ | |
339 | file: resultsFile, | |
340 | folder: resultsFolder, | |
341 | format: 'chart.html', | |
342 | details: true | |
343 | }), | |
344 | Benchmark.save({ | |
345 | file: resultsFile, | |
346 | folder: resultsFolder, | |
347 | format: 'table.html', | |
348 | details: true | |
349 | }) | |
350 | ) | |
18cac485 JB |
351 | .then(() => { |
352 | // eslint-disable-next-line n/no-process-exit | |
353 | return process.exit() | |
354 | }) | |
355 | .catch(err => console.error(err)) |