Commit | Line | Data |
---|---|---|
bdaf31cd JB |
1 | /** |
2 | * Enumeration of worker choice strategies. | |
3 | */ | |
4 | export 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', |
058a9457 JB |
17 | /** |
18 | * Least ELU worker selection strategy. | |
058a9457 JB |
19 | */ |
20 | LEAST_ELU: 'LEAST_ELU', | |
23ff945a JB |
21 | /** |
22 | * Fair share worker selection strategy. | |
23 | */ | |
24 | FAIR_SHARE: 'FAIR_SHARE', | |
b3432a63 JB |
25 | /** |
26 | * Weighted round robin worker selection strategy. | |
27 | */ | |
feec6e8c JB |
28 | WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN', |
29 | /** | |
30 | * Interleaved weighted round robin worker selection strategy. | |
d3127e84 JB |
31 | * |
32 | * @experimental | |
feec6e8c JB |
33 | */ |
34 | INTERLEAVED_WEIGHTED_ROUND_ROBIN: 'INTERLEAVED_WEIGHTED_ROUND_ROBIN' | |
bdaf31cd JB |
35 | } as const) |
36 | ||
37 | /** | |
38 | * Worker choice strategy. | |
39 | */ | |
40 | export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies | |
41 | ||
9adcefab JB |
42 | /** |
43 | * Enumeration of measurements. | |
44 | */ | |
45 | export const Measurements = Object.freeze({ | |
46 | runTime: 'runTime', | |
47 | waitTime: 'waitTime', | |
48 | elu: 'elu' | |
49 | } as const) | |
50 | ||
51 | /** | |
52 | * Measurement. | |
53 | */ | |
54 | export type Measurement = keyof typeof Measurements | |
55 | ||
932fc8be JB |
56 | /** |
57 | * Measurement options. | |
58 | */ | |
9adcefab | 59 | export interface MeasurementOptions { |
932fc8be JB |
60 | /** |
61 | * Set measurement median. | |
62 | */ | |
eb7bf744 | 63 | readonly median: boolean |
932fc8be JB |
64 | } |
65 | ||
ff733df7 JB |
66 | /** |
67 | * Worker choice strategy options. | |
68 | */ | |
69 | export interface WorkerChoiceStrategyOptions { | |
8990357d JB |
70 | /** |
71 | * Measurement to use in worker choice strategy supporting it. | |
9adcefab | 72 | */ |
eb7bf744 | 73 | readonly measurement?: Measurement |
b0623665 | 74 | /** |
932fc8be | 75 | * Runtime options. |
d29bce7c | 76 | * |
932fc8be | 77 | * @defaultValue \{ median: false \} |
b0623665 | 78 | */ |
eb7bf744 | 79 | readonly runTime?: MeasurementOptions |
0567595a | 80 | /** |
932fc8be | 81 | * Wait time options. |
0567595a | 82 | * |
932fc8be | 83 | * @defaultValue \{ median: false \} |
0567595a | 84 | */ |
eb7bf744 | 85 | readonly waitTime?: MeasurementOptions |
5df69fab JB |
86 | /** |
87 | * Event loop utilization options. | |
88 | * | |
89 | * @defaultValue \{ median: false \} | |
90 | */ | |
eb7bf744 | 91 | readonly elu?: MeasurementOptions |
08f3f44c | 92 | /** |
313f98ac | 93 | * Worker weights to use for weighted round robin worker selection strategies. |
98446b39 | 94 | * A weight is tasks maximum execution time in milliseconds for a worker node. |
08f3f44c | 95 | * |
313f98ac | 96 | * @defaultValue Weights computed automatically given the CPU performance. |
08f3f44c | 97 | */ |
00e1bdeb | 98 | weights?: Record<number, number> |
ff733df7 JB |
99 | } |
100 | ||
10fcfaf4 | 101 | /** |
932fc8be | 102 | * Measurement statistics requirements. |
71ebe93b JB |
103 | * |
104 | * @internal | |
10fcfaf4 | 105 | */ |
9adcefab | 106 | export interface MeasurementStatisticsRequirements { |
243a550a | 107 | /** |
64383951 | 108 | * Requires measurement aggregate. |
243a550a | 109 | */ |
932fc8be | 110 | aggregate: boolean |
243a550a | 111 | /** |
64383951 | 112 | * Requires measurement average. |
243a550a | 113 | */ |
932fc8be | 114 | average: boolean |
0567595a | 115 | /** |
64383951 | 116 | * Requires measurement median. |
0567595a | 117 | */ |
932fc8be JB |
118 | median: boolean |
119 | } | |
120 | ||
121 | /** | |
122 | * Pool worker node worker usage statistics requirements. | |
123 | * | |
124 | * @internal | |
125 | */ | |
126 | export interface TaskStatisticsRequirements { | |
0567595a | 127 | /** |
932fc8be | 128 | * Tasks runtime requirements. |
0567595a | 129 | */ |
eb7bf744 | 130 | readonly runTime: MeasurementStatisticsRequirements |
0567595a | 131 | /** |
932fc8be | 132 | * Tasks wait time requirements. |
0567595a | 133 | */ |
eb7bf744 | 134 | readonly waitTime: MeasurementStatisticsRequirements |
62c15a68 | 135 | /** |
5df69fab | 136 | * Tasks event loop utilization requirements. |
62c15a68 | 137 | */ |
eb7bf744 | 138 | readonly elu: MeasurementStatisticsRequirements |
10fcfaf4 JB |
139 | } |
140 | ||
6c6afb84 JB |
141 | /** |
142 | * Strategy policy. | |
247ce01e JB |
143 | * |
144 | * @internal | |
6c6afb84 JB |
145 | */ |
146 | export interface StrategyPolicy { | |
147 | /** | |
b1aae695 | 148 | * Expects tasks execution on the newly created dynamic worker. |
6c6afb84 | 149 | */ |
b1aae695 JB |
150 | readonly dynamicWorkerUsage: boolean |
151 | /** | |
152 | * Expects the newly created dynamic worker to be flagged as ready. | |
153 | */ | |
154 | readonly dynamicWorkerReady: boolean | |
6c6afb84 JB |
155 | } |
156 | ||
bdaf31cd JB |
157 | /** |
158 | * Worker choice strategy interface. | |
922a7350 JB |
159 | * |
160 | * @internal | |
bdaf31cd | 161 | */ |
17393ac8 | 162 | export interface IWorkerChoiceStrategy { |
6c6afb84 JB |
163 | /** |
164 | * Strategy policy. | |
165 | */ | |
166 | readonly strategyPolicy: StrategyPolicy | |
10fcfaf4 | 167 | /** |
87de9ff5 | 168 | * Tasks statistics requirements. |
10fcfaf4 | 169 | */ |
87de9ff5 | 170 | readonly taskStatisticsRequirements: TaskStatisticsRequirements |
ea7a90d3 | 171 | /** |
138d29a8 | 172 | * Resets strategy internals. |
a4958de2 JB |
173 | * |
174 | * @returns `true` if the reset is successful, `false` otherwise. | |
ea7a90d3 | 175 | */ |
4b628b48 | 176 | readonly reset: () => boolean |
138d29a8 | 177 | /** |
c7e196ba | 178 | * Updates the worker node key strategy internals. |
549ee69b | 179 | * This is called after a task has been executed on a worker node. |
138d29a8 JB |
180 | * |
181 | * @returns `true` if the update is successful, `false` otherwise. | |
182 | */ | |
4b628b48 | 183 | readonly update: (workerNodeKey: number) => boolean |
bdaf31cd | 184 | /** |
f06e48d8 | 185 | * Chooses a worker node in the pool and returns its key. |
f6ccb7db JB |
186 | * If no worker nodes are not eligible, `undefined` is returned. |
187 | * If `undefined` is returned, the caller retry. | |
a4958de2 | 188 | * |
b1aae695 | 189 | * @returns The worker node key or `undefined`. |
bdaf31cd | 190 | */ |
b1aae695 | 191 | readonly choose: () => number | undefined |
97a2abc3 | 192 | /** |
c7e196ba | 193 | * Removes the worker node key from strategy internals. |
97a2abc3 | 194 | * |
f06e48d8 | 195 | * @param workerNodeKey - The worker node key. |
138d29a8 | 196 | * @returns `true` if the worker node key is removed, `false` otherwise. |
97a2abc3 | 197 | */ |
4b628b48 | 198 | readonly remove: (workerNodeKey: number) => boolean |
a20f0ba5 JB |
199 | /** |
200 | * Sets the worker choice strategy options. | |
201 | * | |
202 | * @param opts - The worker choice strategy options. | |
203 | */ | |
39618ede | 204 | readonly setOptions: (opts: WorkerChoiceStrategyOptions | undefined) => void |
bdaf31cd | 205 | } |