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 * Worker weights to use for weighted round robin worker selection strategy.
44 * Weight is the tasks maximum average or median runtime in milliseconds.
46 * @defaultValue Computed worker weights automatically given the CPU performance.
48 weights
?: Record
<number, number>
52 * Pool worker tasks usage statistics requirements.
56 export interface RequiredStatistics
{
58 * Require tasks runtime.
62 * Require tasks average runtime.
66 * Require tasks median runtime.
72 * Worker choice strategy interface.
74 export interface IWorkerChoiceStrategy
{
76 * Required tasks usage statistics.
78 readonly requiredStatistics
: RequiredStatistics
80 * Resets strategy internals.
82 * @returns `true` if the reset is successful, `false` otherwise.
86 * Updates the worker node key strategy internals.
88 * @returns `true` if the update is successful, `false` otherwise.
90 update
: (workerNodeKey
: number) => boolean
92 * Chooses a worker node in the pool and returns its key.
94 * @returns The worker node key.
98 * Removes the worker node key from strategy internals.
100 * @param workerNodeKey - The worker node key.
101 * @returns `true` if the worker node key is removed, `false` otherwise.
103 remove
: (workerNodeKey
: number) => boolean
105 * Sets the worker choice strategy options.
107 * @param opts - The worker choice strategy options.
109 setOptions
: (opts
: WorkerChoiceStrategyOptions
) => void