2 * Enumeration of worker choice strategies.
4 export const WorkerChoiceStrategies
: Readonly
<{
5 ROUND_ROBIN
: 'ROUND_ROBIN'
6 LEAST_USED
: 'LEAST_USED'
7 LEAST_BUSY
: 'LEAST_BUSY'
9 FAIR_SHARE
: 'FAIR_SHARE'
10 WEIGHTED_ROUND_ROBIN
: 'WEIGHTED_ROUND_ROBIN'
11 INTERLEAVED_WEIGHTED_ROUND_ROBIN
: 'INTERLEAVED_WEIGHTED_ROUND_ROBIN'
14 * Round robin worker selection strategy.
16 ROUND_ROBIN
: 'ROUND_ROBIN',
18 * Least used worker selection strategy.
20 LEAST_USED
: 'LEAST_USED',
22 * Least busy worker selection strategy.
24 LEAST_BUSY
: 'LEAST_BUSY',
26 * Least ELU worker selection strategy.
28 LEAST_ELU
: 'LEAST_ELU',
30 * Fair share worker selection strategy.
32 FAIR_SHARE
: 'FAIR_SHARE',
34 * Weighted round robin worker selection strategy.
36 WEIGHTED_ROUND_ROBIN
: 'WEIGHTED_ROUND_ROBIN',
38 * Interleaved weighted round robin worker selection strategy.
41 INTERLEAVED_WEIGHTED_ROUND_ROBIN
: 'INTERLEAVED_WEIGHTED_ROUND_ROBIN',
45 * Worker choice strategy.
47 export type WorkerChoiceStrategy
= keyof
typeof WorkerChoiceStrategies
50 * Enumeration of measurements.
52 export const Measurements
: Readonly
<{
65 export type Measurement
= keyof
typeof Measurements
68 * Measurement options.
70 export interface MeasurementOptions
{
72 * Set measurement median.
74 readonly median
: boolean
78 * Worker choice strategy options.
80 export interface WorkerChoiceStrategyOptions
{
82 * Measurement to use in worker choice strategy supporting it.
84 readonly measurement
?: Measurement
87 * @defaultValue \{ median: false \}
89 readonly runTime
?: MeasurementOptions
92 * @defaultValue \{ median: false \}
94 readonly waitTime
?: MeasurementOptions
96 * Event loop utilization options.
97 * @defaultValue \{ median: false \}
99 readonly elu
?: MeasurementOptions
101 * Worker weights to use for weighted round robin worker selection strategies.
102 * A weight is tasks maximum execution time in milliseconds for a worker node.
103 * @defaultValue Weights computed automatically given the CPU performance.
105 weights
?: Record
<number, number>
109 * Measurement statistics requirements.
112 export interface MeasurementStatisticsRequirements
{
114 * Requires measurement aggregate.
118 * Requires measurement average.
122 * Requires measurement median.
128 * Pool worker node worker usage statistics requirements.
131 export interface TaskStatisticsRequirements
{
133 * Tasks runtime requirements.
135 readonly runTime
: MeasurementStatisticsRequirements
137 * Tasks wait time requirements.
139 readonly waitTime
: MeasurementStatisticsRequirements
141 * Tasks event loop utilization requirements.
143 readonly elu
: MeasurementStatisticsRequirements
150 export interface StrategyPolicy
{
152 * Expects tasks execution on the newly created dynamic worker.
154 readonly dynamicWorkerUsage
: boolean
156 * Expects the newly created dynamic worker to be flagged as ready.
158 readonly dynamicWorkerReady
: boolean
162 * Worker choice strategy interface.
165 export interface IWorkerChoiceStrategy
{
169 readonly strategyPolicy
: StrategyPolicy
171 * Tasks statistics requirements.
173 readonly taskStatisticsRequirements
: TaskStatisticsRequirements
175 * Resets strategy internals.
176 * @returns `true` if the reset is successful, `false` otherwise.
178 readonly reset
: () => boolean
180 * Updates the worker node key strategy internals.
181 * This is called after a task has been executed on a worker node.
182 * @returns `true` if the update is successful, `false` otherwise.
184 readonly update
: (workerNodeKey
: number) => boolean
186 * Chooses a worker node in the pool and returns its key.
187 * If no worker nodes are not eligible, `undefined` is returned.
188 * If `undefined` is returned, the caller retry.
189 * @returns The worker node key or `undefined`.
191 readonly choose
: () => number | undefined
193 * Removes the worker node key from strategy internals.
194 * @param workerNodeKey - The worker node key.
195 * @returns `true` if the worker node key is removed, `false` otherwise.
197 readonly remove
: (workerNodeKey
: number) => boolean
199 * Sets the worker choice strategy options.
200 * @param opts - The worker choice strategy options.
202 readonly setOptions
: (opts
: WorkerChoiceStrategyOptions
| undefined) => void