2 * Enumeration of worker choice strategies.
4 export const WorkerChoiceStrategies
= Object.freeze({
6 * Round robin worker selection strategy.
8 ROUND_ROBIN
: 'ROUND_ROBIN',
10 * Less used worker selection strategy.
12 LESS_USED
: 'LESS_USED',
14 * Less busy worker selection strategy.
16 LESS_BUSY
: 'LESS_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.
28 INTERLEAVED_WEIGHTED_ROUND_ROBIN
: 'INTERLEAVED_WEIGHTED_ROUND_ROBIN'
32 * Worker choice strategy.
34 export type WorkerChoiceStrategy
= keyof
typeof WorkerChoiceStrategies
37 * Worker choice strategy options.
39 export interface WorkerChoiceStrategyOptions
{
41 * Use tasks median run time instead of average run time.
47 * Worker weights to use for weighted round robin worker selection strategy.
48 * Weight is the tasks maximum average or median runtime in milliseconds.
50 * @defaultValue Computed worker weights automatically given the CPU performance.
52 weights
?: Record
<number, number>
56 * Pool worker tasks usage statistics requirements.
60 export interface RequiredStatistics
{
62 * Require tasks run time.
66 * Require tasks average run time.
70 * Require tasks median run time.
76 * Worker choice strategy interface.
78 export interface IWorkerChoiceStrategy
{
80 * Required tasks usage statistics.
82 readonly requiredStatistics
: RequiredStatistics
84 * Resets strategy internals.
86 * @returns `true` if the reset is successful, `false` otherwise.
90 * Updates the worker node key strategy internals.
92 * @returns `true` if the update is successful, `false` otherwise.
94 update
: (workerNodeKey
: number) => boolean
96 * Chooses a worker node in the pool and returns its key.
98 * @returns The worker node key.
102 * Removes the worker node key from strategy internals.
104 * @param workerNodeKey - The worker node key.
105 * @returns `true` if the worker node key is removed, `false` otherwise.
107 remove
: (workerNodeKey
: number) => boolean
109 * Sets the worker choice strategy options.
111 * @param opts - The worker choice strategy options.
113 setOptions
: (opts
: WorkerChoiceStrategyOptions
) => void