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.
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 run time instead of average run time.
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 run time.
68 * Require tasks average run time.
72 * Require tasks median run time.
78 * Worker choice strategy interface.
80 export interface IWorkerChoiceStrategy
{
82 * Required tasks usage statistics.
84 readonly requiredStatistics
: RequiredStatistics
86 * Resets strategy internals.
88 * @returns `true` if the reset is successful, `false` otherwise.
92 * Updates the worker node key strategy internals.
94 * @returns `true` if the update is successful, `false` otherwise.
96 update
: (workerNodeKey
: number) => boolean
98 * Chooses a worker node in the pool and returns its key.
100 * @returns The worker node key.
104 * Removes the worker node key from strategy internals.
106 * @param workerNodeKey - The worker node key.
107 * @returns `true` if the worker node key is removed, `false` otherwise.
109 remove
: (workerNodeKey
: number) => boolean
111 * Sets the worker choice strategy options.
113 * @param opts - The worker choice strategy options.
115 setOptions
: (opts
: WorkerChoiceStrategyOptions
) => void