refactor: align worker choice strategy options namespace
[poolifier.git] / src / pools / selection-strategies / selection-strategies-types.ts
index 282e306db18a4c55bb1016e078ce8456ff64d843..26fe436d7a8e587b651458e8359a0b4d0a2e27f9 100644 (file)
@@ -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)
 
 /**
@@ -29,16 +35,32 @@ export const WorkerChoiceStrategies = Object.freeze({
  */
 export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies
 
+/**
+ * Measurement options.
+ */
+interface MeasurementOptions {
+  /**
+   * Set measurement median.
+   */
+  median: boolean
+}
+
 /**
  * Worker choice strategy options.
  */
 export interface WorkerChoiceStrategyOptions {
   /**
-   * Use tasks median runtime instead of average runtime.
+   * Runtime options.
+   *
+   * @defaultValue \{ median: false \}
+   */
+  runTime?: MeasurementOptions
+  /**
+   * Wait time options.
    *
-   * @defaultValue false
+   * @defaultValue \{ median: false \}
    */
-  medRunTime?: boolean
+  waitTime?: MeasurementOptions
   /**
    * Worker weights to use for weighted round robin worker selection strategy.
    * Weight is the tasks maximum average or median runtime in milliseconds.
@@ -49,23 +71,43 @@ export interface WorkerChoiceStrategyOptions {
 }
 
 /**
- * Pool worker tasks usage statistics requirements.
+ * 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 {
+export interface TaskStatisticsRequirements {
   /**
-   * Require tasks runtime.
+   * Tasks runtime requirements.
    */
-  runTime: boolean
+  runTime: MeasurementStatisticsRequirements
   /**
-   * Require tasks average runtime.
+   * Tasks wait time requirements.
    */
-  avgRunTime: boolean
+  waitTime: MeasurementStatisticsRequirements
   /**
-   * Require tasks median runtime.
+   * Event loop utilization.
    */
-  medRunTime: boolean
+  elu: boolean
 }
 
 /**
@@ -73,9 +115,9 @@ export interface RequiredStatistics {
  */
 export interface IWorkerChoiceStrategy {
   /**
-   * Required tasks usage statistics.
+   * Tasks statistics requirements.
    */
-  readonly requiredStatistics: RequiredStatistics
+  readonly taskStatisticsRequirements: TaskStatisticsRequirements
   /**
    * Resets strategy internals.
    *