X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fpools%2Fselection-strategies%2Fselection-strategies-types.ts;h=26fe436d7a8e587b651458e8359a0b4d0a2e27f9;hb=932fc8be063cc15b543ad14c2ab6df0fa4224fba;hp=9acf819b8b858900a1d42a5a681d7f001b152edf;hpb=17393ac83cbf0eacf68ea9efb0a577cc30a5c685;p=poolifier.git diff --git a/src/pools/selection-strategies/selection-strategies-types.ts b/src/pools/selection-strategies/selection-strategies-types.ts index 9acf819b..26fe436d 100644 --- a/src/pools/selection-strategies/selection-strategies-types.ts +++ b/src/pools/selection-strategies/selection-strategies-types.ts @@ -7,13 +7,13 @@ export const WorkerChoiceStrategies = Object.freeze({ */ ROUND_ROBIN: 'ROUND_ROBIN', /** - * Less used worker selection strategy. + * Least used worker selection strategy. */ - LESS_USED: 'LESS_USED', + LEAST_USED: 'LEAST_USED', /** - * Less busy worker selection strategy. + * Least busy worker selection strategy. */ - LESS_BUSY: 'LESS_BUSY', + LEAST_BUSY: 'LEAST_BUSY', /** * Fair share worker selection strategy. */ @@ -21,7 +21,13 @@ export const WorkerChoiceStrategies = Object.freeze({ /** * Weighted round robin worker selection strategy. */ - WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN' + WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN', + /** + * Interleaved weighted round robin worker selection strategy. + * + * @experimental + */ + INTERLEAVED_WEIGHTED_ROUND_ROBIN: 'INTERLEAVED_WEIGHTED_ROUND_ROBIN' } as const) /** @@ -30,11 +36,78 @@ export const WorkerChoiceStrategies = Object.freeze({ export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies /** - * Pool worker tasks usage statistics requirements. + * Measurement options. + */ +interface MeasurementOptions { + /** + * Set measurement median. + */ + median: boolean +} + +/** + * Worker choice strategy options. + */ +export interface WorkerChoiceStrategyOptions { + /** + * Runtime options. + * + * @defaultValue \{ median: false \} + */ + runTime?: MeasurementOptions + /** + * Wait time options. + * + * @defaultValue \{ median: false \} + */ + waitTime?: MeasurementOptions + /** + * Worker weights to use for weighted round robin worker selection strategy. + * Weight is the tasks maximum average or median runtime in milliseconds. + * + * @defaultValue Computed worker weights automatically given the CPU performance. + */ + weights?: Record +} + +/** + * Measurement statistics requirements. + * + * @internal + */ +interface MeasurementStatisticsRequirements { + /** + * Require measurement aggregate. + */ + aggregate: boolean + /** + * Require measurement average. + */ + average: boolean + /** + * Require measurement median. + */ + median: boolean +} + +/** + * Pool worker node worker usage statistics requirements. + * + * @internal */ -export interface RequiredStatistics { - runTime: boolean - avgRunTime: boolean +export interface TaskStatisticsRequirements { + /** + * Tasks runtime requirements. + */ + runTime: MeasurementStatisticsRequirements + /** + * Tasks wait time requirements. + */ + waitTime: MeasurementStatisticsRequirements + /** + * Event loop utilization. + */ + elu: boolean } /** @@ -42,25 +115,38 @@ export interface RequiredStatistics { */ export interface IWorkerChoiceStrategy { /** - * Is the pool bound to the strategy dynamic?. + * Tasks statistics requirements. */ - readonly isDynamicPool: boolean + readonly taskStatisticsRequirements: TaskStatisticsRequirements /** - * Required pool tasks usage statistics. + * Resets strategy internals. + * + * @returns `true` if the reset is successful, `false` otherwise. */ - readonly requiredStatistics: RequiredStatistics + reset: () => boolean /** - * Resets strategy internals (counters, statistics, etc.). + * Updates the worker node key strategy internals. + * + * @returns `true` if the update is successful, `false` otherwise. */ - reset: () => boolean + update: (workerNodeKey: number) => boolean /** - * Chooses a worker in the pool and returns its key. + * Chooses a worker node in the pool and returns its key. + * + * @returns The worker node key. */ choose: () => number /** - * Removes a worker reference from strategy internals. + * Removes the worker node key from strategy internals. + * + * @param workerNodeKey - The worker node key. + * @returns `true` if the worker node key is removed, `false` otherwise. + */ + remove: (workerNodeKey: number) => boolean + /** + * Sets the worker choice strategy options. * - * @param workerKey - The worker key. + * @param opts - The worker choice strategy options. */ - remove: (workerKey: number) => boolean + setOptions: (opts: WorkerChoiceStrategyOptions) => void }