refactor: factor out measurement statistics requirements default
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 30 Jun 2023 14:33:16 +0000 (16:33 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 30 Jun 2023 14:33:16 +0000 (16:33 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/selection-strategies/abstract-worker-choice-strategy.ts
src/pools/selection-strategies/fair-share-worker-choice-strategy.ts
src/pools/selection-strategies/least-busy-worker-choice-strategy.ts
src/pools/selection-strategies/least-elu-worker-choice-strategy.ts
src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts
src/utils.ts

index 5172a181a507fad13940216c933646c616ddb3fa..37759198c882aae1f47256a7f42e19e9261b92a8 100644 (file)
@@ -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
   }
 
   /**
index 9ccec752a3f2c68777f2e6473720b3276185a644..f678f83b9719f93c3c3defd2013dec42fea31a8d 100644 (file)
@@ -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,
index 31fa281aa75dd0dcbf63fffe1d2508f0277d3f6a..7e9d581421319919e865c809df85d06f3c6e305c 100644 (file)
@@ -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 */
index 8394ae7c303144a93855425fe360902774f71bf3..9c29a30a965fa09ec78fd4f916206ceee39f4047 100644 (file)
@@ -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,
index 926900800272fef430ddf68273dcb2992954a85a..2805133092b651ec1efa9d71a5f2f209b0f260f8 100644 (file)
@@ -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
   }
 
   /**
index 6e5f72527cf6d34433bb4c82722be4e68aa646d2..c7efbc22638c59b55bd5e7508f3e19877c3c12a1 100644 (file)
@@ -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.
  *