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 * Fair share worker selection strategy.
20 FAIR_SHARE
: 'FAIR_SHARE',
22 * Weighted round robin worker selection strategy.
24 WEIGHTED_ROUND_ROBIN
: 'WEIGHTED_ROUND_ROBIN',
26 * Interleaved weighted round robin worker selection strategy.
30 INTERLEAVED_WEIGHTED_ROUND_ROBIN
: 'INTERLEAVED_WEIGHTED_ROUND_ROBIN'
34 * Worker choice strategy.
36 export type WorkerChoiceStrategy
= keyof
typeof WorkerChoiceStrategies
39 * Measurement options.
41 interface MeasurementOptions
{
43 * Set measurement median.
49 * Worker choice strategy options.
51 export interface WorkerChoiceStrategyOptions
{
55 * @defaultValue \{ median: false \}
57 runTime
?: MeasurementOptions
61 * @defaultValue \{ median: false \}
63 waitTime
?: MeasurementOptions
65 * Worker weights to use for weighted round robin worker selection strategy.
66 * Weight is the tasks maximum average or median runtime in milliseconds.
68 * @defaultValue Computed worker weights automatically given the CPU performance.
70 weights
?: Record
<number, number>
74 * Measurement statistics requirements.
78 interface MeasurementStatisticsRequirements
{
80 * Require measurement aggregate.
84 * Require measurement average.
88 * Require measurement median.
94 * Pool worker node worker usage statistics requirements.
98 export interface TaskStatisticsRequirements
{
100 * Tasks runtime requirements.
102 runTime
: MeasurementStatisticsRequirements
104 * Tasks wait time requirements.
106 waitTime
: MeasurementStatisticsRequirements
108 * Event loop utilization.
114 * Worker choice strategy interface.
116 export interface IWorkerChoiceStrategy
{
118 * Tasks statistics requirements.
120 readonly taskStatisticsRequirements
: TaskStatisticsRequirements
122 * Resets strategy internals.
124 * @returns `true` if the reset is successful, `false` otherwise.
128 * Updates the worker node key strategy internals.
130 * @returns `true` if the update is successful, `false` otherwise.
132 update
: (workerNodeKey
: number) => boolean
134 * Chooses a worker node in the pool and returns its key.
136 * @returns The worker node key.
140 * Removes the worker node key from strategy internals.
142 * @param workerNodeKey - The worker node key.
143 * @returns `true` if the worker node key is removed, `false` otherwise.
145 remove
: (workerNodeKey
: number) => boolean
147 * Sets the worker choice strategy options.
149 * @param opts - The worker choice strategy options.
151 setOptions
: (opts
: WorkerChoiceStrategyOptions
) => void