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 * Measurement options.
47 interface MeasurementOptions
{
49 * Set measurement median.
55 * Worker choice strategy options.
57 export interface WorkerChoiceStrategyOptions
{
61 * @defaultValue \{ median: false \}
63 runTime
?: MeasurementOptions
67 * @defaultValue \{ median: false \}
69 waitTime
?: MeasurementOptions
71 * Worker weights to use for weighted round robin worker selection strategy.
72 * Weight is the tasks maximum average or median runtime in milliseconds.
74 * @defaultValue Computed worker weights automatically given the CPU performance.
76 weights
?: Record
<number, number>
80 * Measurement statistics requirements.
84 interface MeasurementStatisticsRequirements
{
86 * Require measurement aggregate.
90 * Require measurement average.
94 * Require measurement median.
100 * Pool worker node worker usage statistics requirements.
104 export interface TaskStatisticsRequirements
{
106 * Tasks runtime requirements.
108 runTime
: MeasurementStatisticsRequirements
110 * Tasks wait time requirements.
112 waitTime
: MeasurementStatisticsRequirements
114 * Event loop utilization.
120 * Worker choice strategy interface.
122 export interface IWorkerChoiceStrategy
{
124 * Tasks statistics requirements.
126 readonly taskStatisticsRequirements
: TaskStatisticsRequirements
128 * Resets strategy internals.
130 * @returns `true` if the reset is successful, `false` otherwise.
134 * Updates the worker node key strategy internals.
136 * @returns `true` if the update is successful, `false` otherwise.
138 update
: (workerNodeKey
: number) => boolean
140 * Chooses a worker node in the pool and returns its key.
142 * @returns The worker node key.
146 * Removes the worker node key from strategy internals.
148 * @param workerNodeKey - The worker node key.
149 * @returns `true` if the worker node key is removed, `false` otherwise.
151 remove
: (workerNodeKey
: number) => boolean
153 * Sets the worker choice strategy options.
155 * @param opts - The worker choice strategy options.
157 setOptions
: (opts
: WorkerChoiceStrategyOptions
) => void