1 const Benchmark
= require('benny')
2 const { WorkerChoiceStrategies
} = require('../../lib')
7 } = require('../benchmarks-types')
8 const { buildPool
, runTest
} = require('../benchmarks-utils')
11 const taskExecutions
= 1
13 function: WorkerFunctions
.jsonIntegerSerialization
,
16 const tasksQueuePoolOption
= { enableTasksQueue
: true }
17 const workerChoiceStrategyRoundRobinPoolOption
= {
18 workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
20 const workerChoiceStrategyLessUsedPoolOption
= {
21 workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
23 const workerChoiceStrategyLessBusyPoolOption
= {
24 workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
26 const workerChoiceStrategyWeightedRoundRobinPoolOption
= {
27 workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
29 const workerChoiceStrategyFairSharePoolOption
= {
30 workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
33 const fixedThreadPoolRoundRobin
= buildPool(
37 workerChoiceStrategyRoundRobinPoolOption
40 const fixedThreadPoolRoundRobinTasksQueue
= buildPool(
44 { ...workerChoiceStrategyRoundRobinPoolOption
, ...tasksQueuePoolOption
}
47 const fixedThreadPoolLessUsed
= buildPool(
51 workerChoiceStrategyLessUsedPoolOption
54 const fixedThreadPoolLessBusy
= buildPool(
58 workerChoiceStrategyLessBusyPoolOption
61 const fixedThreadPoolWeightedRoundRobin
= buildPool(
65 workerChoiceStrategyWeightedRoundRobinPoolOption
68 const fixedThreadPoolFairShare
= buildPool(
72 workerChoiceStrategyFairSharePoolOption
75 const dynamicThreadPoolRoundRobin
= buildPool(
79 workerChoiceStrategyRoundRobinPoolOption
82 const dynamicThreadPoolLessUsed
= buildPool(
86 workerChoiceStrategyLessUsedPoolOption
89 const dynamicThreadPoolLessBusy
= buildPool(
93 workerChoiceStrategyLessBusyPoolOption
96 const dynamicThreadPoolWeightedRoundRobin
= buildPool(
100 workerChoiceStrategyWeightedRoundRobinPoolOption
103 const dynamicThreadPoolFairShare
= buildPool(
107 workerChoiceStrategyFairSharePoolOption
110 const fixedClusterPoolRoundRobin
= buildPool(
114 workerChoiceStrategyRoundRobinPoolOption
117 const fixedClusterPoolRoundRobinTasksQueue
= buildPool(
121 { ...workerChoiceStrategyRoundRobinPoolOption
, ...tasksQueuePoolOption
}
124 const fixedClusterPoolLessUsed
= buildPool(
128 workerChoiceStrategyLessUsedPoolOption
131 const fixedClusterPoolLessBusy
= buildPool(
135 workerChoiceStrategyLessBusyPoolOption
138 const fixedClusterPoolWeightedRoundRobin
= buildPool(
142 workerChoiceStrategyWeightedRoundRobinPoolOption
145 const fixedClusterPoolFairShare
= buildPool(
149 workerChoiceStrategyFairSharePoolOption
152 const dynamicClusterPoolRoundRobin
= buildPool(
156 workerChoiceStrategyRoundRobinPoolOption
159 const dynamicClusterPoolLessUsed
= buildPool(
163 workerChoiceStrategyLessUsedPoolOption
166 const dynamicClusterPoolLessBusy
= buildPool(
170 workerChoiceStrategyLessBusyPoolOption
173 const dynamicClusterPoolWeightedRoundRobin
= buildPool(
177 workerChoiceStrategyWeightedRoundRobinPoolOption
180 const dynamicClusterPoolFairShare
= buildPool(
184 workerChoiceStrategyFairSharePoolOption
187 const resultsFile
= 'poolifier'
188 const resultsFolder
= 'benchmarks/internal/results'
192 Benchmark
.add('Fixed:ThreadPool:RoundRobin', async () => {
193 await
runTest(fixedThreadPoolRoundRobin
, {
199 'Fixed:ThreadPool:RoundRobin:{ enableTasksQueue: true }',
201 await
runTest(fixedThreadPoolRoundRobinTasksQueue
, {
207 Benchmark
.add('Fixed:ThreadPool:LessUsed', async () => {
208 await
runTest(fixedThreadPoolLessUsed
, {
213 Benchmark
.add('Fixed:ThreadPool:LessBusy', async () => {
214 await
runTest(fixedThreadPoolLessBusy
, {
219 Benchmark
.add('Fixed:ThreadPool:WeightedRoundRobin', async () => {
220 await
runTest(fixedThreadPoolWeightedRoundRobin
, {
225 Benchmark
.add('Fixed:ThreadPool:FairShare', async () => {
226 await
runTest(fixedThreadPoolFairShare
, {
231 Benchmark
.add('Dynamic:ThreadPool:RoundRobin', async () => {
232 await
runTest(dynamicThreadPoolRoundRobin
, {
237 Benchmark
.add('Dynamic:ThreadPool:LessUsed', async () => {
238 await
runTest(dynamicThreadPoolLessUsed
, {
243 Benchmark
.add('Dynamic:ThreadPool:LessBusy', async () => {
244 await
runTest(dynamicThreadPoolLessBusy
, {
249 Benchmark
.add('Dynamic:ThreadPool:WeightedRoundRobin', async () => {
250 await
runTest(dynamicThreadPoolWeightedRoundRobin
, {
255 Benchmark
.add('Dynamic:ThreadPool:FairShare', async () => {
256 await
runTest(dynamicThreadPoolFairShare
, {
261 Benchmark
.add('Fixed:ClusterPool:RoundRobin', async () => {
262 await
runTest(fixedClusterPoolRoundRobin
, {
268 'Fixed:ClusterPool:RoundRobin:{ enableTasksQueue: true }',
270 await
runTest(fixedClusterPoolRoundRobinTasksQueue
, {
276 Benchmark
.add('Fixed:ClusterPool:LessUsed', async () => {
277 await
runTest(fixedClusterPoolLessUsed
, {
282 Benchmark
.add('Fixed:ClusterPool:LessBusy', async () => {
283 await
runTest(fixedClusterPoolLessBusy
, {
288 Benchmark
.add('Fixed:ClusterPool:WeightedRoundRobin', async () => {
289 await
runTest(fixedClusterPoolWeightedRoundRobin
, {
294 Benchmark
.add('Fixed:ClusterPool:FairShare', async () => {
295 await
runTest(fixedClusterPoolFairShare
, {
300 Benchmark
.add('Dynamic:ClusterPool:RoundRobin', async () => {
301 await
runTest(dynamicClusterPoolRoundRobin
, {
306 Benchmark
.add('Dynamic:ClusterPool:LessUsed', async () => {
307 await
runTest(dynamicClusterPoolLessUsed
, {
312 Benchmark
.add('Dynamic:ClusterPool:LessBusy', async () => {
313 await
runTest(dynamicClusterPoolLessBusy
, {
318 Benchmark
.add('Dynamic:ClusterPool:WeightedRoundRobin', async () => {
319 await
runTest(dynamicClusterPoolWeightedRoundRobin
, {
324 Benchmark
.add('Dynamic:ClusterPool:FairShare', async () => {
325 await
runTest(dynamicClusterPoolFairShare
, {
331 Benchmark
.complete(),
334 folder
: resultsFolder
,
340 folder
: resultsFolder
,
341 format
: 'chart.html',
346 folder
: resultsFolder
,
347 format
: 'table.html',
352 // eslint-disable-next-line n/no-process-exit
353 return process
.exit()
355 .catch(err
=> console
.error(err
))