Add fair sharing worker choice strategy
[poolifier.git] / benchmarks / internal / cluster / dynamic.js
1 const {
2 DynamicClusterPool,
3 WorkerChoiceStrategies
4 } = require('../../../lib/index')
5 const { runPoolifierTest } = require('../benchmark-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_RECENTLY_USED }
21 )
22
23 const dynamicPoolFairShare = new DynamicClusterPool(
24 size / 2,
25 size * 3,
26 './benchmarks/internal/cluster/worker.js',
27 { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
28 )
29
30 async function dynamicClusterTest (
31 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
32 ) {
33 return runPoolifierTest(dynamicPool, { tasks, workerData })
34 }
35
36 async function dynamicClusterTestLessRecentlyUsed (
37 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
38 ) {
39 return runPoolifierTest(dynamicPoolLessRecentlyUsed, { tasks, workerData })
40 }
41
42 async function dynamicClusterTestFairShare (
43 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
44 ) {
45 return runPoolifierTest(dynamicPoolFairShare, { tasks, workerData })
46 }
47
48 module.exports = {
49 dynamicClusterTest,
50 dynamicClusterTestFairShare,
51 dynamicClusterTestLessRecentlyUsed
52 }