feat: add less busy worker choice strategy to internal benchmarks
[poolifier.git] / benchmarks / internal / cluster / dynamic.js
1 const {
2 DynamicClusterPool,
3 WorkerChoiceStrategies
4 } = require('../../../lib/index')
5 const { runPoolifierTest } = require('../../benchmarks-utils')
6
7 const size = 30
8 const numberOfTasks = 1
9
10 const dynamicPool = new DynamicClusterPool(
11 size / 2,
12 size * 3,
13 './benchmarks/internal/cluster/worker.js'
14 )
15
16 const dynamicPoolLessUsed = new DynamicClusterPool(
17 size / 2,
18 size * 3,
19 './benchmarks/internal/cluster/worker.js',
20 { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
21 )
22
23 const dynamicPoolLessBusy = new DynamicClusterPool(
24 size / 2,
25 size * 3,
26 './benchmarks/internal/cluster/worker.js',
27 { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
28 )
29
30 const dynamicPoolWeightedRoundRobin = new DynamicClusterPool(
31 size / 2,
32 size * 3,
33 './benchmarks/internal/cluster/worker.js',
34 { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
35 )
36
37 const dynamicPoolFairShare = new DynamicClusterPool(
38 size / 2,
39 size * 3,
40 './benchmarks/internal/cluster/worker.js',
41 { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
42 )
43
44 async function dynamicClusterTest (
45 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
46 ) {
47 return runPoolifierTest(dynamicPool, { tasks, workerData })
48 }
49
50 async function dynamicClusterTestLessUsed (
51 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
52 ) {
53 return runPoolifierTest(dynamicPoolLessUsed, { tasks, workerData })
54 }
55
56 async function dynamicClusterTestLessBusy (
57 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
58 ) {
59 return runPoolifierTest(dynamicPoolLessBusy, { tasks, workerData })
60 }
61
62 async function dynamicClusterTestWeightedRoundRobin (
63 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
64 ) {
65 return runPoolifierTest(dynamicPoolWeightedRoundRobin, { tasks, workerData })
66 }
67
68 async function dynamicClusterTestFairShare (
69 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
70 ) {
71 return runPoolifierTest(dynamicPoolFairShare, { tasks, workerData })
72 }
73
74 module.exports = {
75 dynamicClusterTest,
76 dynamicClusterTestLessUsed,
77 dynamicClusterTestLessBusy,
78 dynamicClusterTestWeightedRoundRobin,
79 dynamicClusterTestFairShare
80 }