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 | ||
932fc8be JB |
44 | /** |
45 | * Measurement options. | |
46 | */ | |
47 | interface MeasurementOptions { | |
48 | /** | |
49 | * Set measurement median. | |
50 | */ | |
51 | median: boolean | |
52 | } | |
53 | ||
ff733df7 JB |
54 | /** |
55 | * Worker choice strategy options. | |
56 | */ | |
57 | export interface WorkerChoiceStrategyOptions { | |
b0623665 | 58 | /** |
932fc8be | 59 | * Runtime options. |
d29bce7c | 60 | * |
932fc8be | 61 | * @defaultValue \{ median: false \} |
b0623665 | 62 | */ |
932fc8be | 63 | runTime?: MeasurementOptions |
0567595a | 64 | /** |
932fc8be | 65 | * Wait time options. |
0567595a | 66 | * |
932fc8be | 67 | * @defaultValue \{ median: false \} |
0567595a | 68 | */ |
932fc8be | 69 | waitTime?: MeasurementOptions |
5df69fab JB |
70 | /** |
71 | * Event loop utilization options. | |
72 | * | |
73 | * @defaultValue \{ median: false \} | |
74 | */ | |
75 | elu?: MeasurementOptions | |
08f3f44c JB |
76 | /** |
77 | * Worker weights to use for weighted round robin worker selection strategy. | |
78 | * Weight is the tasks maximum average or median runtime in milliseconds. | |
79 | * | |
80 | * @defaultValue Computed worker weights automatically given the CPU performance. | |
81 | */ | |
82 | weights?: Record<number, number> | |
ff733df7 JB |
83 | } |
84 | ||
10fcfaf4 | 85 | /** |
932fc8be | 86 | * Measurement statistics requirements. |
71ebe93b JB |
87 | * |
88 | * @internal | |
10fcfaf4 | 89 | */ |
932fc8be | 90 | interface MeasurementStatisticsRequirements { |
243a550a | 91 | /** |
932fc8be | 92 | * Require measurement aggregate. |
243a550a | 93 | */ |
932fc8be | 94 | aggregate: boolean |
243a550a | 95 | /** |
932fc8be | 96 | * Require measurement average. |
243a550a | 97 | */ |
932fc8be | 98 | average: boolean |
0567595a | 99 | /** |
932fc8be | 100 | * Require measurement median. |
0567595a | 101 | */ |
932fc8be JB |
102 | median: boolean |
103 | } | |
104 | ||
105 | /** | |
106 | * Pool worker node worker usage statistics requirements. | |
107 | * | |
108 | * @internal | |
109 | */ | |
110 | export interface TaskStatisticsRequirements { | |
0567595a | 111 | /** |
932fc8be | 112 | * Tasks runtime requirements. |
0567595a | 113 | */ |
932fc8be | 114 | runTime: MeasurementStatisticsRequirements |
0567595a | 115 | /** |
932fc8be | 116 | * Tasks wait time requirements. |
0567595a | 117 | */ |
932fc8be | 118 | waitTime: MeasurementStatisticsRequirements |
62c15a68 | 119 | /** |
5df69fab | 120 | * Tasks event loop utilization requirements. |
62c15a68 | 121 | */ |
5df69fab | 122 | elu: MeasurementStatisticsRequirements |
10fcfaf4 JB |
123 | } |
124 | ||
bdaf31cd JB |
125 | /** |
126 | * Worker choice strategy interface. | |
bdaf31cd | 127 | */ |
17393ac8 | 128 | export interface IWorkerChoiceStrategy { |
10fcfaf4 | 129 | /** |
87de9ff5 | 130 | * Tasks statistics requirements. |
10fcfaf4 | 131 | */ |
87de9ff5 | 132 | readonly taskStatisticsRequirements: TaskStatisticsRequirements |
ea7a90d3 | 133 | /** |
138d29a8 | 134 | * Resets strategy internals. |
a4958de2 JB |
135 | * |
136 | * @returns `true` if the reset is successful, `false` otherwise. | |
ea7a90d3 | 137 | */ |
78cea37e | 138 | reset: () => boolean |
138d29a8 | 139 | /** |
c7e196ba | 140 | * Updates the worker node key strategy internals. |
138d29a8 JB |
141 | * |
142 | * @returns `true` if the update is successful, `false` otherwise. | |
143 | */ | |
a4958de2 | 144 | update: (workerNodeKey: number) => boolean |
bdaf31cd | 145 | /** |
f06e48d8 | 146 | * Chooses a worker node in the pool and returns its key. |
a4958de2 JB |
147 | * |
148 | * @returns The worker node key. | |
bdaf31cd | 149 | */ |
c923ce56 | 150 | choose: () => number |
97a2abc3 | 151 | /** |
c7e196ba | 152 | * Removes the worker node key from strategy internals. |
97a2abc3 | 153 | * |
f06e48d8 | 154 | * @param workerNodeKey - The worker node key. |
138d29a8 | 155 | * @returns `true` if the worker node key is removed, `false` otherwise. |
97a2abc3 | 156 | */ |
f06e48d8 | 157 | remove: (workerNodeKey: number) => boolean |
a20f0ba5 JB |
158 | /** |
159 | * Sets the worker choice strategy options. | |
160 | * | |
161 | * @param opts - The worker choice strategy options. | |
162 | */ | |
163 | setOptions: (opts: WorkerChoiceStrategyOptions) => void | |
bdaf31cd | 164 | } |