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