refactor: rename a worker choice strategy
[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 dynamicPoolLessRecentlyUsed = new DynamicClusterPool(
17 size / 2,
18 size * 3,
19 './benchmarks/internal/cluster/worker.js',
20 { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
21 )
22
23 const dynamicPoolWeightedRoundRobin = new DynamicClusterPool(
24 size / 2,
25 size * 3,
26 './benchmarks/internal/cluster/worker.js',
27 { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
28 )
29
30 const dynamicPoolFairShare = new DynamicClusterPool(
31 size / 2,
32 size * 3,
33 './benchmarks/internal/cluster/worker.js',
34 { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
35 )
36
37 async function dynamicClusterTest (
38 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
39 ) {
40 return runPoolifierTest(dynamicPool, { tasks, workerData })
41 }
42
43 async function dynamicClusterTestLessRecentlyUsed (
44 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
45 ) {
46 return runPoolifierTest(dynamicPoolLessRecentlyUsed, { tasks, workerData })
47 }
48
49 async function dynamicClusterTestWeightedRoundRobin (
50 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
51 ) {
52 return runPoolifierTest(dynamicPoolWeightedRoundRobin, { tasks, workerData })
53 }
54
55 async function dynamicClusterTestFairShare (
56 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
57 ) {
58 return runPoolifierTest(dynamicPoolFairShare, { tasks, workerData })
59 }
60
61 module.exports = {
62 dynamicClusterTest,
63 dynamicClusterTestLessRecentlyUsed,
64 dynamicClusterTestWeightedRoundRobin,
65 dynamicClusterTestFairShare
66 }