From 3c93feb918b47943d801029fad82a61469e40127 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 30 Jun 2023 16:33:16 +0200 Subject: [PATCH] refactor: factor out measurement statistics requirements default MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../abstract-worker-choice-strategy.ts | 23 ++++++------------- .../fair-share-worker-choice-strategy.ts | 11 ++++----- .../least-busy-worker-choice-strategy.ts | 11 ++++----- .../least-elu-worker-choice-strategy.ts | 17 +++++--------- ...hted-round-robin-worker-choice-strategy.ts | 17 +++++--------- src/utils.ts | 15 +++++++++++- 6 files changed, 43 insertions(+), 51 deletions(-) diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index 5172a181..37759198 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -1,5 +1,8 @@ import { cpus } from 'node:os' -import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils' +import { + DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, + DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS +} from '../../utils' import type { IPool } from '../pool' import type { IWorker } from '../worker' import type { @@ -38,21 +41,9 @@ export abstract class AbstractWorkerChoiceStrategy< /** @inheritDoc */ public readonly taskStatisticsRequirements: TaskStatisticsRequirements = { - runTime: { - aggregate: false, - average: false, - median: false - }, - waitTime: { - aggregate: false, - average: false, - median: false - }, - elu: { - aggregate: false, - average: false, - median: false - } + runTime: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, + waitTime: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, + elu: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } /** diff --git a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts index 9ccec752..f678f83b 100644 --- a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts @@ -1,4 +1,7 @@ -import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils' +import { + DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, + DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS +} from '../../utils' import type { IPool } from '../pool' import type { IWorker } from '../worker' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' @@ -31,11 +34,7 @@ export class FairShareWorkerChoiceStrategy< average: true, median: false }, - waitTime: { - aggregate: false, - average: false, - median: false - }, + waitTime: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, elu: { aggregate: true, average: true, diff --git a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts index 31fa281a..7e9d5814 100644 --- a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts @@ -1,4 +1,7 @@ -import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils' +import { + DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, + DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS +} from '../../utils' import type { IPool } from '../pool' import type { IWorker } from '../worker' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' @@ -34,11 +37,7 @@ export class LeastBusyWorkerChoiceStrategy< average: false, median: false }, - elu: { - aggregate: false, - average: false, - median: false - } + elu: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } /** @inheritDoc */ diff --git a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts index 8394ae7c..9c29a30a 100644 --- a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts @@ -1,4 +1,7 @@ -import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils' +import { + DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, + DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS +} from '../../utils' import type { IPool } from '../pool' import type { IWorker } from '../worker' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' @@ -24,16 +27,8 @@ export class LeastEluWorkerChoiceStrategy< implements IWorkerChoiceStrategy { /** @inheritDoc */ public readonly taskStatisticsRequirements: TaskStatisticsRequirements = { - runTime: { - aggregate: false, - average: false, - median: false - }, - waitTime: { - aggregate: false, - average: false, - median: false - }, + runTime: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, + waitTime: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, elu: { aggregate: true, average: false, diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index 92690080..28051330 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -1,6 +1,9 @@ import type { IWorker } from '../worker' import type { IPool } from '../pool' -import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils' +import { + DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, + DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS +} from '../../utils' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' import type { IWorkerChoiceStrategy, @@ -36,16 +39,8 @@ export class WeightedRoundRobinWorkerChoiceStrategy< average: true, median: false }, - waitTime: { - aggregate: false, - average: false, - median: false - }, - elu: { - aggregate: false, - average: false, - median: false - } + waitTime: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, + elu: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } /** diff --git a/src/utils.ts b/src/utils.ts index 6e5f7252..c7efbc22 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,7 @@ -import type { WorkerChoiceStrategyOptions } from './pools/selection-strategies/selection-strategies-types' +import type { + MeasurementStatisticsRequirements, + WorkerChoiceStrategyOptions +} from './pools/selection-strategies/selection-strategies-types' /** * An intentional empty function. @@ -17,6 +20,16 @@ export const DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS: WorkerChoiceStrategyOptions elu: { median: false } } +/** + * Default measurement statistics requirements. + */ +export const DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS: MeasurementStatisticsRequirements = + { + aggregate: false, + average: false, + median: false + } + /** * Compute the median of the given data set. * -- 2.34.1