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 * Worker choice strategy options.
41 export interface WorkerChoiceStrategyOptions
{
43 * Use tasks median runtime instead of average runtime.
49 * Use tasks median wait time instead of average runtime.
55 * Worker weights to use for weighted round robin worker selection strategy.
56 * Weight is the tasks maximum average or median runtime in milliseconds.
58 * @defaultValue Computed worker weights automatically given the CPU performance.
60 weights
?: Record
<number, number>
64 * Pool worker node worker usage statistics requirements.
68 export interface TaskStatistics
{
70 * Require tasks runtime.
74 * Require tasks average runtime.
78 * Require tasks median runtime.
82 * Require tasks wait time.
86 * Require tasks average wait time.
90 * Require tasks median wait time.
94 * Event loop utilization.
100 * Worker choice strategy interface.
102 export interface IWorkerChoiceStrategy
{
104 * Required tasks statistics.
106 readonly taskStatistics
: TaskStatistics
108 * Resets strategy internals.
110 * @returns `true` if the reset is successful, `false` otherwise.
114 * Updates the worker node key strategy internals.
116 * @returns `true` if the update is successful, `false` otherwise.
118 update
: (workerNodeKey
: number) => boolean
120 * Chooses a worker node in the pool and returns its key.
122 * @returns The worker node key.
126 * Removes the worker node key from strategy internals.
128 * @param workerNodeKey - The worker node key.
129 * @returns `true` if the worker node key is removed, `false` otherwise.
131 remove
: (workerNodeKey
: number) => boolean
133 * Sets the worker choice strategy options.
135 * @param opts - The worker choice strategy options.
137 setOptions
: (opts
: WorkerChoiceStrategyOptions
) => void