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 * Measurement to use in worker choice strategy supporting it.
73 readonly measurement
?: Measurement
77 * @defaultValue \{ median: false \}
79 readonly runTime
?: MeasurementOptions
83 * @defaultValue \{ median: false \}
85 readonly waitTime
?: MeasurementOptions
87 * Event loop utilization options.
89 * @defaultValue \{ median: false \}
91 readonly elu
?: MeasurementOptions
93 * Worker weights to use for weighted round robin worker selection strategies.
94 * A weight is tasks maximum execution time in milliseconds for a worker node.
96 * @defaultValue Weights computed automatically given the CPU performance.
98 weights
?: Record
<number, number>
102 * Measurement statistics requirements.
106 export interface MeasurementStatisticsRequirements
{
108 * Requires measurement aggregate.
112 * Requires measurement average.
116 * Requires measurement median.
122 * Pool worker node worker usage statistics requirements.
126 export interface TaskStatisticsRequirements
{
128 * Tasks runtime requirements.
130 readonly runTime
: MeasurementStatisticsRequirements
132 * Tasks wait time requirements.
134 readonly waitTime
: MeasurementStatisticsRequirements
136 * Tasks event loop utilization requirements.
138 readonly elu
: MeasurementStatisticsRequirements
146 export interface StrategyPolicy
{
148 * Expects tasks execution on the newly created dynamic worker.
150 readonly dynamicWorkerUsage
: boolean
152 * Expects the newly created dynamic worker to be flagged as ready.
154 readonly dynamicWorkerReady
: boolean
158 * Worker choice strategy interface.
162 export interface IWorkerChoiceStrategy
{
166 readonly strategyPolicy
: StrategyPolicy
168 * Tasks statistics requirements.
170 readonly taskStatisticsRequirements
: TaskStatisticsRequirements
172 * Resets strategy internals.
174 * @returns `true` if the reset is successful, `false` otherwise.
176 readonly reset
: () => boolean
178 * Updates the worker node key strategy internals.
179 * This is called after a task has been executed on a worker node.
181 * @returns `true` if the update is successful, `false` otherwise.
183 readonly update
: (workerNodeKey
: number) => boolean
185 * Chooses a worker node in the pool and returns its key.
186 * If no worker nodes are not eligible, `undefined` is returned.
187 * 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.
195 * @param workerNodeKey - The worker node key.
196 * @returns `true` if the worker node key is removed, `false` otherwise.
198 readonly remove
: (workerNodeKey
: number) => boolean
200 * Sets the worker choice strategy options.
202 * @param opts - The worker choice strategy options.
204 readonly setOptions
: (opts
: WorkerChoiceStrategyOptions
| undefined) => void