refactor: partially revert strategies optimization
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 18 Jun 2023 16:02:56 +0000 (18:02 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 18 Jun 2023 16:02:56 +0000 (18:02 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
CHANGELOG.md
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/least-used-worker-choice-strategy.ts

index 40a1eac2e3a5bbf876a31dab7c1fb765c87f42a0..9058bed670386b13d551213ac93b50187b5597be 100644 (file)
@@ -14,7 +14,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Changed
 
 - Optimize O(1) queue implementation.
-- Optimize worker choice strategies: pre-choose the worker node key by executing the choice algorithm after tasks submission.
 
 ## [2.6.2] - 2023-06-12
 
index 39da59a0f2c2d0a16c58e9f4f8b9ce91cc915b92..7b3ad3f7516f2b9522aca6acf3ec6b0356aabac3 100644 (file)
@@ -66,6 +66,11 @@ export class FairShareWorkerChoiceStrategy<
   /** @inheritDoc */
   public update (workerNodeKey: number): boolean {
     this.computeWorkerVirtualTaskEndTimestamp(workerNodeKey)
+    return true
+  }
+
+  /** @inheritDoc */
+  public choose (): number {
     let minWorkerVirtualTaskEndTimestamp = Infinity
     for (const [workerNodeKey] of this.pool.workerNodes.entries()) {
       if (this.workersVirtualTaskEndTimestamp[workerNodeKey] == null) {
@@ -78,11 +83,6 @@ export class FairShareWorkerChoiceStrategy<
         this.nextWorkerNodeId = workerNodeKey
       }
     }
-    return true
-  }
-
-  /** @inheritDoc */
-  public choose (): number {
     return this.nextWorkerNodeId
   }
 
index aafc07dd6f8ac8f8faa47742bdda2e096449fd55..84476eedaf0c434f5bcce23aa7ca694f1bf9d267 100644 (file)
@@ -57,6 +57,11 @@ export class LeastBusyWorkerChoiceStrategy<
 
   /** @inheritDoc */
   public update (): boolean {
+    return true
+  }
+
+  /** @inheritDoc */
+  public choose (): number {
     let minTime = Infinity
     for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
       const workerTime =
@@ -70,11 +75,6 @@ export class LeastBusyWorkerChoiceStrategy<
         this.nextWorkerNodeId = workerNodeKey
       }
     }
-    return true
-  }
-
-  /** @inheritDoc */
-  public choose (): number {
     return this.nextWorkerNodeId
   }
 
index 5df742a665d5d9b5ed838beb887e426da43ade07..30491dce6fd6962c11547a7fd2494e9a733775da 100644 (file)
@@ -57,6 +57,11 @@ export class LeastEluWorkerChoiceStrategy<
 
   /** @inheritDoc */
   public update (): boolean {
+    return true
+  }
+
+  /** @inheritDoc */
+  public choose (): number {
     let minWorkerElu = Infinity
     for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
       const workerUsage = workerNode.workerUsage
@@ -69,11 +74,6 @@ export class LeastEluWorkerChoiceStrategy<
         this.nextWorkerNodeId = workerNodeKey
       }
     }
-    return true
-  }
-
-  /** @inheritDoc */
-  public choose (): number {
     return this.nextWorkerNodeId
   }
 
index 922659d33e6947e08e12df7b3bf0cd64dd55bf7a..aaa6c21dc0f3dc7654a4b4d7986d44f809ef96b0 100644 (file)
@@ -37,6 +37,11 @@ export class LeastUsedWorkerChoiceStrategy<
 
   /** @inheritDoc */
   public update (): boolean {
+    return true
+  }
+
+  /** @inheritDoc */
+  public choose (): number {
     let minNumberOfTasks = Infinity
     for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
       const workerTaskStatistics = workerNode.workerUsage.tasks
@@ -52,11 +57,6 @@ export class LeastUsedWorkerChoiceStrategy<
         this.nextWorkerNodeId = workerNodeKey
       }
     }
-    return true
-  }
-
-  /** @inheritDoc */
-  public choose (): number {
     return this.nextWorkerNodeId
   }