build: update volta node version
[poolifier.git] / src / pools / selection-strategies / selection-strategies-types.ts
CommitLineData
bdaf31cd
JB
1/**
2 * Enumeration of worker choice strategies.
3 */
4export const WorkerChoiceStrategies = Object.freeze({
5 /**
6 * Round robin worker selection strategy.
7 */
8 ROUND_ROBIN: 'ROUND_ROBIN',
9 /**
e4543b14 10 * Least used worker selection strategy.
bdaf31cd 11 */
e4543b14 12 LEAST_USED: 'LEAST_USED',
168c526f 13 /**
e4543b14 14 * Least busy worker selection strategy.
168c526f 15 */
e4543b14 16 LEAST_BUSY: 'LEAST_BUSY',
23ff945a
JB
17 /**
18 * Fair share worker selection strategy.
19 */
20 FAIR_SHARE: 'FAIR_SHARE',
b3432a63
JB
21 /**
22 * Weighted round robin worker selection strategy.
23 */
feec6e8c
JB
24 WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN',
25 /**
26 * Interleaved weighted round robin worker selection strategy.
d3127e84
JB
27 *
28 * @experimental
feec6e8c
JB
29 */
30 INTERLEAVED_WEIGHTED_ROUND_ROBIN: 'INTERLEAVED_WEIGHTED_ROUND_ROBIN'
bdaf31cd
JB
31} as const)
32
33/**
34 * Worker choice strategy.
35 */
36export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies
37
ff733df7
JB
38/**
39 * Worker choice strategy options.
40 */
41export interface WorkerChoiceStrategyOptions {
b0623665 42 /**
9e45c2c4 43 * Use tasks median runtime instead of average runtime.
d29bce7c
JB
44 *
45 * @defaultValue false
b0623665 46 */
ff733df7 47 medRunTime?: boolean
0567595a 48 /**
e6606302 49 * Use tasks median wait time instead of average runtime.
0567595a
JB
50 *
51 * @defaultValue false
52 */
53 medWaitTime?: boolean
08f3f44c
JB
54 /**
55 * Worker weights to use for weighted round robin worker selection strategy.
56 * Weight is the tasks maximum average or median runtime in milliseconds.
57 *
58 * @defaultValue Computed worker weights automatically given the CPU performance.
59 */
60 weights?: Record<number, number>
ff733df7
JB
61}
62
10fcfaf4 63/**
a4e07f72 64 * Pool worker node worker usage statistics requirements.
71ebe93b
JB
65 *
66 * @internal
10fcfaf4 67 */
87de9ff5 68export interface TaskStatisticsRequirements {
243a550a 69 /**
9e775f96 70 * Require tasks runtime.
243a550a 71 */
10fcfaf4 72 runTime: boolean
243a550a 73 /**
9e775f96 74 * Require tasks average runtime.
243a550a 75 */
c6bd2650 76 avgRunTime: boolean
243a550a 77 /**
9e775f96 78 * Require tasks median runtime.
243a550a 79 */
78099a15 80 medRunTime: boolean
0567595a
JB
81 /**
82 * Require tasks wait time.
83 */
84 waitTime: boolean
85 /**
86 * Require tasks average wait time.
87 */
88 avgWaitTime: boolean
89 /**
90 * Require tasks median wait time.
91 */
92 medWaitTime: boolean
62c15a68
JB
93 /**
94 * Event loop utilization.
95 */
96 elu: boolean
10fcfaf4
JB
97}
98
bdaf31cd
JB
99/**
100 * Worker choice strategy interface.
bdaf31cd 101 */
17393ac8 102export interface IWorkerChoiceStrategy {
10fcfaf4 103 /**
87de9ff5 104 * Tasks statistics requirements.
10fcfaf4 105 */
87de9ff5 106 readonly taskStatisticsRequirements: TaskStatisticsRequirements
ea7a90d3 107 /**
138d29a8 108 * Resets strategy internals.
a4958de2
JB
109 *
110 * @returns `true` if the reset is successful, `false` otherwise.
ea7a90d3 111 */
78cea37e 112 reset: () => boolean
138d29a8 113 /**
c7e196ba 114 * Updates the worker node key strategy internals.
138d29a8
JB
115 *
116 * @returns `true` if the update is successful, `false` otherwise.
117 */
a4958de2 118 update: (workerNodeKey: number) => boolean
bdaf31cd 119 /**
f06e48d8 120 * Chooses a worker node in the pool and returns its key.
a4958de2
JB
121 *
122 * @returns The worker node key.
bdaf31cd 123 */
c923ce56 124 choose: () => number
97a2abc3 125 /**
c7e196ba 126 * Removes the worker node key from strategy internals.
97a2abc3 127 *
f06e48d8 128 * @param workerNodeKey - The worker node key.
138d29a8 129 * @returns `true` if the worker node key is removed, `false` otherwise.
97a2abc3 130 */
f06e48d8 131 remove: (workerNodeKey: number) => boolean
a20f0ba5
JB
132 /**
133 * Sets the worker choice strategy options.
134 *
135 * @param opts - The worker choice strategy options.
136 */
137 setOptions: (opts: WorkerChoiceStrategyOptions) => void
bdaf31cd 138}