-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
selection-strategies-types.ts
138 lines (134 loc) · 3.03 KB
/
selection-strategies-types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* Enumeration of worker choice strategies.
*/
export const WorkerChoiceStrategies = Object.freeze({
/**
* Round robin worker selection strategy.
*/
ROUND_ROBIN: 'ROUND_ROBIN',
/**
* Least used worker selection strategy.
*/
LEAST_USED: 'LEAST_USED',
/**
* Least busy worker selection strategy.
*/
LEAST_BUSY: 'LEAST_BUSY',
/**
* Fair share worker selection strategy.
*/
FAIR_SHARE: 'FAIR_SHARE',
/**
* Weighted round robin worker selection strategy.
*/
WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN',
/**
* Interleaved weighted round robin worker selection strategy.
*
* @experimental
*/
INTERLEAVED_WEIGHTED_ROUND_ROBIN: 'INTERLEAVED_WEIGHTED_ROUND_ROBIN'
} as const)
/**
* Worker choice strategy.
*/
export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies
/**
* Worker choice strategy options.
*/
export interface WorkerChoiceStrategyOptions {
/**
* Use tasks median runtime instead of average runtime.
*
* @defaultValue false
*/
medRunTime?: boolean
/**
* Use tasks median wait time instead of average runtime.
*
* @defaultValue false
*/
medWaitTime?: boolean
/**
* Worker weights to use for weighted round robin worker selection strategy.
* Weight is the tasks maximum average or median runtime in milliseconds.
*
* @defaultValue Computed worker weights automatically given the CPU performance.
*/
weights?: Record<number, number>
}
/**
* Pool worker tasks usage statistics requirements.
*
* @internal
*/
export interface TaskStatistics {
/**
* Require tasks runtime.
*/
runTime: boolean
/**
* Require tasks average runtime.
*/
avgRunTime: boolean
/**
* Require tasks median runtime.
*/
medRunTime: boolean
/**
* Require tasks wait time.
*/
waitTime: boolean
/**
* Require tasks average wait time.
*/
avgWaitTime: boolean
/**
* Require tasks median wait time.
*/
medWaitTime: boolean
/**
* Event loop utilization.
*/
elu: boolean
}
/**
* Worker choice strategy interface.
*/
export interface IWorkerChoiceStrategy {
/**
* Required tasks statistics.
*/
readonly taskStatistics: TaskStatistics
/**
* Resets strategy internals.
*
* @returns `true` if the reset is successful, `false` otherwise.
*/
reset: () => boolean
/**
* Updates the worker node key strategy internals.
*
* @returns `true` if the update is successful, `false` otherwise.
*/
update: (workerNodeKey: number) => boolean
/**
* Chooses a worker node in the pool and returns its key.
*
* @returns The worker node key.
*/
choose: () => number
/**
* Removes the worker node key from strategy internals.
*
* @param workerNodeKey - The worker node key.
* @returns `true` if the worker node key is removed, `false` otherwise.
*/
remove: (workerNodeKey: number) => boolean
/**
* Sets the worker choice strategy options.
*
* @param opts - The worker choice strategy options.
*/
setOptions: (opts: WorkerChoiceStrategyOptions) => void
}