feat: add less busy worker choice strategy
[poolifier.git] / benchmarks / internal / thread / fixed.js
1 const {
2 FixedThreadPool,
3 WorkerChoiceStrategies
4 } = require('../../../lib/index')
5 const { runPoolifierTest } = require('../../benchmarks-utils')
6
7 const size = 30
8 const numberOfTasks = 1
9
10 const fixedPool = new FixedThreadPool(
11 size,
12 './benchmarks/internal/thread/worker.js'
13 )
14
15 const fixedPoolLessUsed = new FixedThreadPool(
16 size,
17 './benchmarks/internal/thread/worker.js',
18 { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
19 )
20
21 const fixedPoolWeightedRoundRobin = new FixedThreadPool(
22 size,
23 './benchmarks/internal/thread/worker.js',
24 { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
25 )
26
27 const fixedPoolFairShare = new FixedThreadPool(
28 size,
29 './benchmarks/internal/thread/worker.js',
30 { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
31 )
32
33 async function fixedThreadTest (
34 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
35 ) {
36 return runPoolifierTest(fixedPool, { tasks, workerData })
37 }
38
39 async function fixedThreadTestLessUsed (
40 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
41 ) {
42 return runPoolifierTest(fixedPoolLessUsed, { tasks, workerData })
43 }
44
45 async function fixedThreadTestWeightedRoundRobin (
46 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
47 ) {
48 return runPoolifierTest(fixedPoolWeightedRoundRobin, { tasks, workerData })
49 }
50
51 async function fixedThreadTestFairShare (
52 { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
53 ) {
54 return runPoolifierTest(fixedPoolFairShare, { tasks, workerData })
55 }
56
57 module.exports = {
58 fixedThreadTest,
59 fixedThreadTestLessUsed,
60 fixedThreadTestWeightedRoundRobin,
61 fixedThreadTestFairShare
62 }