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.
22 LEAST_ELU
: 'LEAST_ELU',
24 * Fair share worker selection strategy.
26 FAIR_SHARE
: 'FAIR_SHARE',
28 * Weighted round robin worker selection strategy.
30 WEIGHTED_ROUND_ROBIN
: 'WEIGHTED_ROUND_ROBIN',
32 * Interleaved weighted round robin worker selection strategy.
36 INTERLEAVED_WEIGHTED_ROUND_ROBIN
: 'INTERLEAVED_WEIGHTED_ROUND_ROBIN'
40 * Worker choice strategy.
42 export type WorkerChoiceStrategy
= keyof
typeof WorkerChoiceStrategies
45 * Enumeration of measurements.
47 export const Measurements
= Object.freeze({
56 export type Measurement
= keyof
typeof Measurements
59 * Measurement options.
61 export interface MeasurementOptions
{
63 * Set measurement median.
65 readonly median
: boolean
69 * Worker choice strategy options.
71 export interface WorkerChoiceStrategyOptions
{
73 * Number of worker choice retries to perform if no worker is eligible.
77 readonly choiceRetries
?: number
79 * Measurement to use in worker choice strategy supporting it.
81 readonly measurement
?: Measurement
85 * @defaultValue \{ median: false \}
87 readonly runTime
?: MeasurementOptions
91 * @defaultValue \{ median: false \}
93 readonly waitTime
?: MeasurementOptions
95 * Event loop utilization options.
97 * @defaultValue \{ median: false \}
99 readonly elu
?: MeasurementOptions
101 * Worker weights to use for weighted round robin worker selection strategy.
102 * Weight is the tasks maximum average or median runtime in milliseconds.
104 * @defaultValue Computed worker weights automatically given the CPU performance.
106 readonly weights
?: Record
<number, number>
110 * Measurement statistics requirements.
114 export interface MeasurementStatisticsRequirements
{
116 * Requires measurement aggregate.
120 * Requires measurement average.
124 * Requires measurement median.
130 * Pool worker node worker usage statistics requirements.
134 export interface TaskStatisticsRequirements
{
136 * Tasks runtime requirements.
138 readonly runTime
: MeasurementStatisticsRequirements
140 * Tasks wait time requirements.
142 readonly waitTime
: MeasurementStatisticsRequirements
144 * Tasks event loop utilization requirements.
146 readonly elu
: MeasurementStatisticsRequirements
154 export interface StrategyPolicy
{
156 * Expects tasks execution on the newly created dynamic worker.
158 readonly dynamicWorkerUsage
: boolean
160 * Expects the newly created dynamic worker to be flagged as ready.
162 readonly dynamicWorkerReady
: boolean
166 * Worker choice strategy interface.
170 export interface IWorkerChoiceStrategy
{
174 readonly strategyPolicy
: StrategyPolicy
176 * Tasks statistics requirements.
178 readonly taskStatisticsRequirements
: TaskStatisticsRequirements
180 * Resets strategy internals.
182 * @returns `true` if the reset is successful, `false` otherwise.
184 readonly reset
: () => boolean
186 * Updates the worker node key strategy internals.
188 * @returns `true` if the update is successful, `false` otherwise.
190 readonly update
: (workerNodeKey
: number) => boolean
192 * Chooses a worker node in the pool and returns its key.
193 * If the worker node is not eligible, `undefined` is returned.
195 * @returns The worker node key or `undefined`.
197 readonly choose
: () => number | undefined
199 * Removes the worker node key from strategy internals.
201 * @param workerNodeKey - The worker node key.
202 * @returns `true` if the worker node key is removed, `false` otherwise.
204 readonly remove
: (workerNodeKey
: number) => boolean
206 * Sets the worker choice strategy options.
208 * @param opts - The worker choice strategy options.
210 readonly setOptions
: (opts
: WorkerChoiceStrategyOptions
) => void