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( | |
34 | PoolTypes.FIXED, | |
35 | poolSize, | |
36 | WorkerTypes.THREAD, | |
37 | workerChoiceStrategyRoundRobinPoolOption | |
38 | ) | |
39 | ||
40 | const fixedThreadPoolRoundRobinTasksQueue = buildPool( | |
41 | PoolTypes.FIXED, | |
42 | poolSize, | |
43 | WorkerTypes.THREAD, | |
44 | { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption } | |
45 | ) | |
46 | ||
47 | const fixedThreadPoolLessUsed = buildPool( | |
48 | PoolTypes.FIXED, | |
49 | poolSize, | |
50 | WorkerTypes.THREAD, | |
51 | workerChoiceStrategyLessUsedPoolOption | |
52 | ) | |
53 | ||
54 | const fixedThreadPoolLessBusy = buildPool( | |
55 | PoolTypes.FIXED, | |
56 | poolSize, | |
57 | WorkerTypes.THREAD, | |
58 | workerChoiceStrategyLessBusyPoolOption | |
59 | ) | |
60 | ||
61 | const fixedThreadPoolWeightedRoundRobin = buildPool( | |
62 | PoolTypes.FIXED, | |
63 | poolSize, | |
64 | WorkerTypes.THREAD, | |
65 | workerChoiceStrategyWeightedRoundRobinPoolOption | |
66 | ) | |
67 | ||
68 | const fixedThreadPoolFairShare = buildPool( | |
69 | PoolTypes.FIXED, | |
70 | poolSize, | |
71 | WorkerTypes.THREAD, | |
72 | workerChoiceStrategyFairSharePoolOption | |
73 | ) | |
74 | ||
75 | const dynamicThreadPoolRoundRobin = buildPool( | |
76 | PoolTypes.DYNAMIC, | |
77 | poolSize, | |
78 | WorkerTypes.THREAD, | |
79 | workerChoiceStrategyRoundRobinPoolOption | |
80 | ) | |
81 | ||
82 | const dynamicThreadPoolLessUsed = buildPool( | |
83 | PoolTypes.DYNAMIC, | |
84 | poolSize, | |
85 | WorkerTypes.THREAD, | |
86 | workerChoiceStrategyLessUsedPoolOption | |
87 | ) | |
88 | ||
89 | const dynamicThreadPoolLessBusy = buildPool( | |
90 | PoolTypes.DYNAMIC, | |
91 | poolSize, | |
92 | WorkerTypes.THREAD, | |
93 | workerChoiceStrategyLessBusyPoolOption | |
94 | ) | |
95 | ||
96 | const dynamicThreadPoolWeightedRoundRobin = buildPool( | |
97 | PoolTypes.DYNAMIC, | |
98 | poolSize, | |
99 | WorkerTypes.THREAD, | |
100 | workerChoiceStrategyWeightedRoundRobinPoolOption | |
101 | ) | |
102 | ||
103 | const dynamicThreadPoolFairShare = buildPool( | |
104 | PoolTypes.DYNAMIC, | |
105 | poolSize, | |
106 | WorkerTypes.THREAD, | |
107 | workerChoiceStrategyFairSharePoolOption | |
108 | ) | |
109 | ||
110 | const fixedClusterPoolRoundRobin = buildPool( | |
111 | PoolTypes.FIXED, | |
112 | poolSize, | |
113 | WorkerTypes.CLUSTER, | |
114 | workerChoiceStrategyRoundRobinPoolOption | |
115 | ) | |
116 | ||
117 | const fixedClusterPoolRoundRobinTasksQueue = buildPool( | |
118 | PoolTypes.FIXED, | |
119 | poolSize, | |
120 | WorkerTypes.CLUSTER, | |
121 | { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption } | |
122 | ) | |
123 | ||
124 | const fixedClusterPoolLessUsed = buildPool( | |
125 | PoolTypes.FIXED, | |
126 | poolSize, | |
127 | WorkerTypes.CLUSTER, | |
128 | workerChoiceStrategyLessUsedPoolOption | |
129 | ) | |
130 | ||
131 | const fixedClusterPoolLessBusy = buildPool( | |
132 | PoolTypes.FIXED, | |
133 | poolSize, | |
134 | WorkerTypes.CLUSTER, | |
135 | workerChoiceStrategyLessBusyPoolOption | |
136 | ) | |
137 | ||
138 | const fixedClusterPoolWeightedRoundRobin = buildPool( | |
139 | PoolTypes.FIXED, | |
140 | poolSize, | |
141 | WorkerTypes.CLUSTER, | |
142 | workerChoiceStrategyWeightedRoundRobinPoolOption | |
143 | ) | |
144 | ||
145 | const fixedClusterPoolFairShare = buildPool( | |
146 | PoolTypes.FIXED, | |
147 | poolSize, | |
148 | WorkerTypes.CLUSTER, | |
149 | workerChoiceStrategyFairSharePoolOption | |
150 | ) | |
151 | ||
152 | const dynamicClusterPoolRoundRobin = buildPool( | |
153 | PoolTypes.DYNAMIC, | |
154 | poolSize, | |
155 | WorkerTypes.CLUSTER, | |
156 | workerChoiceStrategyRoundRobinPoolOption | |
157 | ) | |
158 | ||
159 | const dynamicClusterPoolLessUsed = buildPool( | |
160 | PoolTypes.DYNAMIC, | |
161 | poolSize, | |
162 | WorkerTypes.CLUSTER, | |
163 | workerChoiceStrategyLessUsedPoolOption | |
164 | ) | |
165 | ||
166 | const dynamicClusterPoolLessBusy = buildPool( | |
167 | PoolTypes.DYNAMIC, | |
168 | poolSize, | |
169 | WorkerTypes.CLUSTER, | |
170 | workerChoiceStrategyLessBusyPoolOption | |
171 | ) | |
172 | ||
173 | const dynamicClusterPoolWeightedRoundRobin = buildPool( | |
174 | PoolTypes.DYNAMIC, | |
175 | poolSize, | |
176 | WorkerTypes.CLUSTER, | |
177 | workerChoiceStrategyWeightedRoundRobinPoolOption | |
178 | ) | |
179 | ||
180 | const dynamicClusterPoolFairShare = buildPool( | |
181 | PoolTypes.DYNAMIC, | |
182 | poolSize, | |
183 | WorkerTypes.CLUSTER, | |
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)) |