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 * Event loop utilization options.
73 * @defaultValue \{ median: false \}
75 elu
?: MeasurementOptions
77 * Worker weights to use for weighted round robin worker selection strategy.
78 * Weight is the tasks maximum average or median runtime in milliseconds.
80 * @defaultValue Computed worker weights automatically given the CPU performance.
82 weights
?: Record
<number, number>
86 * Measurement statistics requirements.
90 interface MeasurementStatisticsRequirements
{
92 * Require measurement aggregate.
96 * Require measurement average.
100 * Require measurement median.
106 * Pool worker node worker usage statistics requirements.
110 export interface TaskStatisticsRequirements
{
112 * Tasks runtime requirements.
114 runTime
: MeasurementStatisticsRequirements
116 * Tasks wait time requirements.
118 waitTime
: MeasurementStatisticsRequirements
120 * Tasks event loop utilization requirements.
122 elu
: MeasurementStatisticsRequirements
126 * Worker choice strategy interface.
128 export interface IWorkerChoiceStrategy
{
130 * Tasks statistics requirements.
132 readonly taskStatisticsRequirements
: TaskStatisticsRequirements
134 * Resets strategy internals.
136 * @returns `true` if the reset is successful, `false` otherwise.
140 * Updates the worker node key strategy internals.
142 * @returns `true` if the update is successful, `false` otherwise.
144 update
: (workerNodeKey
: number) => boolean
146 * Chooses a worker node in the pool and returns its key.
148 * @returns The worker node key.
152 * Removes the worker node key from strategy internals.
154 * @param workerNodeKey - The worker node key.
155 * @returns `true` if the worker node key is removed, `false` otherwise.
157 remove
: (workerNodeKey
: number) => boolean
159 * Sets the worker choice strategy options.
161 * @param opts - The worker choice strategy options.
163 setOptions
: (opts
: WorkerChoiceStrategyOptions
) => void