2 * Enumeration of worker choice strategies.
4 export const WorkerChoiceStrategies
= Object.freeze({
6 * Round robin worker selection strategy.
8 ROUND_ROBIN
: 'ROUND_ROBIN',
10 * Least used worker selection strategy.
12 LEAST_USED
: 'LEAST_USED',
14 * Least busy worker selection strategy.
16 LEAST_BUSY
: 'LEAST_BUSY',
18 * Least ELU worker selection strategy.
20 LEAST_ELU
: 'LEAST_ELU',
22 * Fair share worker selection strategy.
24 FAIR_SHARE
: 'FAIR_SHARE',
26 * Weighted round robin worker selection strategy.
28 WEIGHTED_ROUND_ROBIN
: 'WEIGHTED_ROUND_ROBIN',
30 * Interleaved weighted round robin worker selection strategy.
34 INTERLEAVED_WEIGHTED_ROUND_ROBIN
: 'INTERLEAVED_WEIGHTED_ROUND_ROBIN'
38 * Worker choice strategy.
40 export type WorkerChoiceStrategy
= keyof
typeof WorkerChoiceStrategies
43 * Enumeration of measurements.
45 export const Measurements
= Object.freeze({
54 export type Measurement
= keyof
typeof Measurements
57 * Measurement options.
59 export interface MeasurementOptions
{
61 * Set measurement median.
63 readonly median
: boolean
67 * Worker choice strategy options.
69 export interface WorkerChoiceStrategyOptions
{
71 * Number of worker choice retries to perform if no worker is eligible.
75 readonly retries
?: number
77 * Measurement to use in worker choice strategy supporting it.
79 readonly measurement
?: Measurement
83 * @defaultValue \{ median: false \}
85 readonly runTime
?: MeasurementOptions
89 * @defaultValue \{ median: false \}
91 readonly waitTime
?: MeasurementOptions
93 * Event loop utilization options.
95 * @defaultValue \{ median: false \}
97 readonly elu
?: MeasurementOptions
99 * Worker weights to use for weighted round robin worker selection strategies.
100 * A weight is tasks maximum execution time in milliseconds for a worker node.
102 * @defaultValue Weights computed automatically given the CPU performance.
104 readonly weights
?: Record
<number, number>
108 * 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.
132 export interface TaskStatisticsRequirements
{
134 * Tasks runtime requirements.
136 readonly runTime
: MeasurementStatisticsRequirements
138 * Tasks wait time requirements.
140 readonly waitTime
: MeasurementStatisticsRequirements
142 * Tasks event loop utilization requirements.
144 readonly elu
: MeasurementStatisticsRequirements
152 export interface StrategyPolicy
{
154 * Expects tasks execution on the newly created dynamic worker.
156 readonly dynamicWorkerUsage
: boolean
158 * Expects the newly created dynamic worker to be flagged as ready.
160 readonly dynamicWorkerReady
: boolean
164 * Worker choice strategy interface.
168 export interface IWorkerChoiceStrategy
{
172 readonly strategyPolicy
: StrategyPolicy
174 * Tasks statistics requirements.
176 readonly taskStatisticsRequirements
: TaskStatisticsRequirements
178 * Resets strategy internals.
180 * @returns `true` if the reset is successful, `false` otherwise.
182 readonly reset
: () => boolean
184 * Updates the worker node key strategy internals.
186 * @returns `true` if the update is successful, `false` otherwise.
188 readonly update
: (workerNodeKey
: number) => boolean
190 * Chooses a worker node in the pool and returns its key.
191 * If the worker node is not eligible, `undefined` is returned.
193 * @returns The worker node key or `undefined`.
195 readonly choose
: () => number | undefined
197 * Removes the worker node key from strategy internals.
199 * @param workerNodeKey - The worker node key.
200 * @returns `true` if the worker node key is removed, `false` otherwise.
202 readonly remove
: (workerNodeKey
: number) => boolean
204 * Sets the worker choice strategy options.
206 * @param opts - The worker choice strategy options.
208 readonly setOptions
: (opts
: WorkerChoiceStrategyOptions
) => void