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.
42 INTERLEAVED_WEIGHTED_ROUND_ROBIN
: 'INTERLEAVED_WEIGHTED_ROUND_ROBIN'
46 * Worker choice strategy.
48 export type WorkerChoiceStrategy
= keyof
typeof WorkerChoiceStrategies
51 * Enumeration of measurements.
53 export const Measurements
: Readonly
<{
66 export type Measurement
= keyof
typeof Measurements
69 * Measurement options.
71 export interface MeasurementOptions
{
73 * Set measurement median.
75 readonly median
: boolean
79 * Worker choice strategy options.
81 export interface WorkerChoiceStrategyOptions
{
83 * Measurement to use in worker choice strategy supporting it.
85 readonly measurement
?: Measurement
89 * @defaultValue \{ median: false \}
91 readonly runTime
?: MeasurementOptions
95 * @defaultValue \{ median: false \}
97 readonly waitTime
?: MeasurementOptions
99 * Event loop utilization options.
101 * @defaultValue \{ median: false \}
103 readonly elu
?: MeasurementOptions
105 * Worker weights to use for weighted round robin worker selection strategies.
106 * A weight is tasks maximum execution time in milliseconds for a worker node.
108 * @defaultValue Weights computed automatically given the CPU performance.
110 weights
?: Record
<number, number>
114 * Measurement statistics requirements.
118 export interface MeasurementStatisticsRequirements
{
120 * Requires measurement aggregate.
124 * Requires measurement average.
128 * Requires measurement median.
134 * Pool worker node worker usage statistics requirements.
138 export interface TaskStatisticsRequirements
{
140 * Tasks runtime requirements.
142 readonly runTime
: MeasurementStatisticsRequirements
144 * Tasks wait time requirements.
146 readonly waitTime
: MeasurementStatisticsRequirements
148 * Tasks event loop utilization requirements.
150 readonly elu
: MeasurementStatisticsRequirements
158 export interface StrategyPolicy
{
160 * Expects tasks execution on the newly created dynamic worker.
162 readonly dynamicWorkerUsage
: boolean
164 * Expects the newly created dynamic worker to be flagged as ready.
166 readonly dynamicWorkerReady
: boolean
170 * Worker choice strategy interface.
174 export interface IWorkerChoiceStrategy
{
178 readonly strategyPolicy
: StrategyPolicy
180 * Tasks statistics requirements.
182 readonly taskStatisticsRequirements
: TaskStatisticsRequirements
184 * Resets strategy internals.
186 * @returns `true` if the reset is successful, `false` otherwise.
188 readonly reset
: () => boolean
190 * Updates the worker node key strategy internals.
191 * This is called after a task has been executed on a worker node.
193 * @returns `true` if the update is successful, `false` otherwise.
195 readonly update
: (workerNodeKey
: number) => boolean
197 * Chooses a worker node in the pool and returns its key.
198 * If no worker nodes are not eligible, `undefined` is returned.
199 * If `undefined` is returned, the caller retry.
201 * @returns The worker node key or `undefined`.
203 readonly choose
: () => number | undefined
205 * Removes the worker node key from strategy internals.
207 * @param workerNodeKey - The worker node key.
208 * @returns `true` if the worker node key is removed, `false` otherwise.
210 readonly remove
: (workerNodeKey
: number) => boolean
212 * Sets the worker choice strategy options.
214 * @param opts - The worker choice strategy options.
216 readonly setOptions
: (opts
: WorkerChoiceStrategyOptions
| undefined) => void