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 * Worker choice strategy options.
47 export interface WorkerChoiceStrategyOptions
{
49 * Use tasks median runtime instead of average runtime.
55 * Use tasks median wait time instead of average runtime.
61 * Worker weights to use for weighted round robin worker selection strategy.
62 * Weight is the tasks maximum average or median runtime in milliseconds.
64 * @defaultValue Computed worker weights automatically given the CPU performance.
66 weights
?: Record
<number, number>
70 * Pool worker tasks usage statistics requirements.
74 export interface TaskStatistics
{
76 * Require tasks runtime.
80 * Require tasks average runtime.
84 * Require tasks median runtime.
88 * Require tasks wait time.
92 * Require tasks average wait time.
96 * Require tasks median wait time.
100 * Event loop utilization.
106 * Worker choice strategy interface.
108 export interface IWorkerChoiceStrategy
{
110 * Required tasks statistics.
112 readonly taskStatistics
: TaskStatistics
114 * Resets strategy internals.
116 * @returns `true` if the reset is successful, `false` otherwise.
120 * Updates the worker node key strategy internals.
122 * @returns `true` if the update is successful, `false` otherwise.
124 update
: (workerNodeKey
: number) => boolean
126 * Chooses a worker node in the pool and returns its key.
128 * @returns The worker node key.
132 * Removes the worker node key from strategy internals.
134 * @param workerNodeKey - The worker node key.
135 * @returns `true` if the worker node key is removed, `false` otherwise.
137 remove
: (workerNodeKey
: number) => boolean
139 * Sets the worker choice strategy options.
141 * @param opts - The worker choice strategy options.
143 setOptions
: (opts
: WorkerChoiceStrategyOptions
) => void