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 | /** | |
737c6d97 | 10 | * Less used worker selection strategy. |
bdaf31cd | 11 | */ |
737c6d97 | 12 | LESS_USED: 'LESS_USED', |
168c526f JB |
13 | /** |
14 | * Less busy worker selection strategy. | |
15 | */ | |
16 | LESS_BUSY: 'LESS_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 | */ | |
36 | export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies | |
37 | ||
ff733df7 JB |
38 | /** |
39 | * Worker choice strategy options. | |
40 | */ | |
41 | export interface WorkerChoiceStrategyOptions { | |
b0623665 JB |
42 | /** |
43 | * Use tasks median run time instead of average run time. | |
d29bce7c JB |
44 | * |
45 | * @defaultValue false | |
b0623665 | 46 | */ |
ff733df7 | 47 | medRunTime?: boolean |
08f3f44c JB |
48 | /** |
49 | * Worker weights to use for weighted round robin worker selection strategy. | |
50 | * Weight is the tasks maximum average or median runtime in milliseconds. | |
51 | * | |
52 | * @defaultValue Computed worker weights automatically given the CPU performance. | |
53 | */ | |
54 | weights?: Record<number, number> | |
ff733df7 JB |
55 | } |
56 | ||
10fcfaf4 | 57 | /** |
9cd39dd4 | 58 | * Pool worker tasks usage statistics requirements. |
71ebe93b JB |
59 | * |
60 | * @internal | |
10fcfaf4 | 61 | */ |
78cea37e | 62 | export interface RequiredStatistics { |
243a550a JB |
63 | /** |
64 | * Require tasks run time. | |
65 | */ | |
10fcfaf4 | 66 | runTime: boolean |
243a550a JB |
67 | /** |
68 | * Require tasks average run time. | |
69 | */ | |
c6bd2650 | 70 | avgRunTime: boolean |
243a550a JB |
71 | /** |
72 | * Require tasks median run time. | |
73 | */ | |
78099a15 | 74 | medRunTime: boolean |
10fcfaf4 JB |
75 | } |
76 | ||
bdaf31cd JB |
77 | /** |
78 | * Worker choice strategy interface. | |
bdaf31cd | 79 | */ |
17393ac8 | 80 | export interface IWorkerChoiceStrategy { |
10fcfaf4 | 81 | /** |
f06e48d8 | 82 | * Required tasks usage statistics. |
10fcfaf4 | 83 | */ |
ea7a90d3 JB |
84 | readonly requiredStatistics: RequiredStatistics |
85 | /** | |
138d29a8 | 86 | * Resets strategy internals. |
a4958de2 JB |
87 | * |
88 | * @returns `true` if the reset is successful, `false` otherwise. | |
ea7a90d3 | 89 | */ |
78cea37e | 90 | reset: () => boolean |
138d29a8 | 91 | /** |
c7e196ba | 92 | * Updates the worker node key strategy internals. |
138d29a8 JB |
93 | * |
94 | * @returns `true` if the update is successful, `false` otherwise. | |
95 | */ | |
a4958de2 | 96 | update: (workerNodeKey: number) => boolean |
bdaf31cd | 97 | /** |
f06e48d8 | 98 | * Chooses a worker node in the pool and returns its key. |
a4958de2 JB |
99 | * |
100 | * @returns The worker node key. | |
bdaf31cd | 101 | */ |
c923ce56 | 102 | choose: () => number |
97a2abc3 | 103 | /** |
c7e196ba | 104 | * Removes the worker node key from strategy internals. |
97a2abc3 | 105 | * |
f06e48d8 | 106 | * @param workerNodeKey - The worker node key. |
138d29a8 | 107 | * @returns `true` if the worker node key is removed, `false` otherwise. |
97a2abc3 | 108 | */ |
f06e48d8 | 109 | remove: (workerNodeKey: number) => boolean |
a20f0ba5 JB |
110 | /** |
111 | * Sets the worker choice strategy options. | |
112 | * | |
113 | * @param opts - The worker choice strategy options. | |
114 | */ | |
115 | setOptions: (opts: WorkerChoiceStrategyOptions) => void | |
bdaf31cd | 116 | } |