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'
28 * Worker choice strategy.
30 export type WorkerChoiceStrategy
= keyof
typeof WorkerChoiceStrategies
33 * Worker choice strategy options.
35 export interface WorkerChoiceStrategyOptions
{
37 * Use tasks median runtime instead of average runtime.
43 * Use tasks median wait time instead of average runtime.
49 * Worker weights to use for weighted round robin worker selection strategy.
50 * Weight is the tasks maximum average or median runtime in milliseconds.
52 * @defaultValue Computed worker weights automatically given the CPU performance.
54 weights
?: Record
<number, number>
58 * Pool worker tasks usage statistics requirements.
62 export interface RequiredStatistics
{
64 * Require tasks runtime.
68 * Require tasks average runtime.
72 * Require tasks median runtime.
76 * Require tasks wait time.
80 * Require tasks average wait time.
84 * Require tasks median wait time.
90 * Worker choice strategy interface.
92 export interface IWorkerChoiceStrategy
{
94 * Required tasks usage statistics.
96 readonly requiredStatistics
: RequiredStatistics
98 * Resets strategy internals.
100 * @returns `true` if the reset is successful, `false` otherwise.
104 * Updates the worker node key strategy internals.
106 * @returns `true` if the update is successful, `false` otherwise.
108 update
: (workerNodeKey
: number) => boolean
110 * Chooses a worker node in the pool and returns its key.
112 * @returns The worker node key.
116 * Removes the worker node key from strategy internals.
118 * @param workerNodeKey - The worker node key.
119 * @returns `true` if the worker node key is removed, `false` otherwise.
121 remove
: (workerNodeKey
: number) => boolean
123 * Sets the worker choice strategy options.
125 * @param opts - The worker choice strategy options.
127 setOptions
: (opts
: WorkerChoiceStrategyOptions
) => void