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 * Enumeration of measurements.
47 export const Measurements
= Object.freeze({
56 export type Measurement
= keyof
typeof Measurements
59 * Measurement options.
61 export interface MeasurementOptions
{
63 * Set measurement median.
69 * Worker choice strategy options.
71 export interface WorkerChoiceStrategyOptions
{
73 * Measurement to use for worker choice strategy.
75 measurement
?: Measurement
79 * @defaultValue \{ median: false \}
81 runTime
?: MeasurementOptions
85 * @defaultValue \{ median: false \}
87 waitTime
?: MeasurementOptions
89 * Event loop utilization options.
91 * @defaultValue \{ median: false \}
93 elu
?: MeasurementOptions
95 * Worker weights to use for weighted round robin worker selection strategy.
96 * Weight is the tasks maximum average or median runtime in milliseconds.
98 * @defaultValue Computed worker weights automatically given the CPU performance.
100 weights
?: Record
<number, number>
104 * Measurement statistics requirements.
108 export interface MeasurementStatisticsRequirements
{
110 * Require measurement aggregate.
114 * Require measurement average.
118 * Require measurement median.
124 * Pool worker node worker usage statistics requirements.
128 export interface TaskStatisticsRequirements
{
130 * Tasks runtime requirements.
132 runTime
: MeasurementStatisticsRequirements
134 * Tasks wait time requirements.
136 waitTime
: MeasurementStatisticsRequirements
138 * Tasks event loop utilization requirements.
140 elu
: MeasurementStatisticsRequirements
148 export interface StrategyPolicy
{
150 * Expect direct usage of dynamic worker.
152 useDynamicWorker
: boolean
156 * Worker choice strategy interface.
158 export interface IWorkerChoiceStrategy
{
162 readonly strategyPolicy
: StrategyPolicy
164 * Tasks statistics requirements.
166 readonly taskStatisticsRequirements
: TaskStatisticsRequirements
168 * Resets strategy internals.
170 * @returns `true` if the reset is successful, `false` otherwise.
174 * Updates the worker node key strategy internals.
176 * @returns `true` if the update is successful, `false` otherwise.
178 update
: (workerNodeKey
: number) => boolean
180 * Chooses a worker node in the pool and returns its key.
182 * @returns The worker node key.
186 * Removes the worker node key from strategy internals.
188 * @param workerNodeKey - The worker node key.
189 * @returns `true` if the worker node key is removed, `false` otherwise.
191 remove
: (workerNodeKey
: number) => boolean
193 * Sets the worker choice strategy options.
195 * @param opts - The worker choice strategy options.
197 setOptions
: (opts
: WorkerChoiceStrategyOptions
) => void