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 | */ | |
24 | WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN' | |
bdaf31cd JB |
25 | } as const) |
26 | ||
27 | /** | |
28 | * Worker choice strategy. | |
29 | */ | |
30 | export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies | |
31 | ||
ff733df7 JB |
32 | /** |
33 | * Worker choice strategy options. | |
34 | */ | |
35 | export interface WorkerChoiceStrategyOptions { | |
b0623665 JB |
36 | /** |
37 | * Use tasks median run time instead of average run time. | |
d29bce7c JB |
38 | * |
39 | * @defaultValue false | |
b0623665 | 40 | */ |
ff733df7 | 41 | medRunTime?: boolean |
08f3f44c JB |
42 | /** |
43 | * Worker weights to use for weighted round robin worker selection strategy. | |
44 | * Weight is the tasks maximum average or median runtime in milliseconds. | |
45 | * | |
46 | * @defaultValue Computed worker weights automatically given the CPU performance. | |
47 | */ | |
48 | weights?: Record<number, number> | |
ff733df7 JB |
49 | } |
50 | ||
10fcfaf4 | 51 | /** |
9cd39dd4 | 52 | * Pool worker tasks usage statistics requirements. |
71ebe93b JB |
53 | * |
54 | * @internal | |
10fcfaf4 | 55 | */ |
78cea37e | 56 | export interface RequiredStatistics { |
243a550a JB |
57 | /** |
58 | * Require tasks run time. | |
59 | */ | |
10fcfaf4 | 60 | runTime: boolean |
243a550a JB |
61 | /** |
62 | * Require tasks average run time. | |
63 | */ | |
c6bd2650 | 64 | avgRunTime: boolean |
243a550a JB |
65 | /** |
66 | * Require tasks median run time. | |
67 | */ | |
78099a15 | 68 | medRunTime: boolean |
10fcfaf4 JB |
69 | } |
70 | ||
bdaf31cd JB |
71 | /** |
72 | * Worker choice strategy interface. | |
bdaf31cd | 73 | */ |
17393ac8 | 74 | export interface IWorkerChoiceStrategy { |
10fcfaf4 | 75 | /** |
f06e48d8 | 76 | * Required tasks usage statistics. |
10fcfaf4 | 77 | */ |
ea7a90d3 JB |
78 | readonly requiredStatistics: RequiredStatistics |
79 | /** | |
a6f7f1b4 | 80 | * Resets strategy internals (counters, statistics, etc.). |
ea7a90d3 | 81 | */ |
78cea37e | 82 | reset: () => boolean |
bdaf31cd | 83 | /** |
f06e48d8 | 84 | * Chooses a worker node in the pool and returns its key. |
bdaf31cd | 85 | */ |
c923ce56 | 86 | choose: () => number |
97a2abc3 | 87 | /** |
f06e48d8 | 88 | * Removes a worker node key from strategy internals. |
97a2abc3 | 89 | * |
f06e48d8 | 90 | * @param workerNodeKey - The worker node key. |
97a2abc3 | 91 | */ |
f06e48d8 | 92 | remove: (workerNodeKey: number) => boolean |
a20f0ba5 JB |
93 | /** |
94 | * Sets the worker choice strategy options. | |
95 | * | |
96 | * @param opts - The worker choice strategy options. | |
97 | */ | |
98 | setOptions: (opts: WorkerChoiceStrategyOptions) => void | |
bdaf31cd | 99 | } |