WRR strategy: cleanups
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 14 Oct 2022 21:50:25 +0000 (23:50 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 14 Oct 2022 21:50:25 +0000 (23:50 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts

index 2b9cfc74536851ee39f0616d92932323c730031c..38033132190e1e08ea625e943530d9f488328fc1 100644 (file)
@@ -77,19 +77,18 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
     const workerTaskWeight =
       this.workersTaskRunTime.get(chosenWorker)?.weight ??
       this.defaultWorkerWeight
-    if (
-      (this.workersTaskRunTime.get(chosenWorker)?.runTime ?? 0) <
-      workerTaskWeight
-    ) {
+    const workerTaskRunTime =
+      this.workersTaskRunTime.get(chosenWorker)?.runTime ?? 0
+    if (workerTaskRunTime < workerTaskWeight) {
       this.setWorkerTaskRunTime(
         chosenWorker,
         workerTaskWeight,
-        (this.workersTaskRunTime.get(chosenWorker)?.runTime ?? 0) +
+        workerTaskRunTime +
           (this.getWorkerVirtualTaskRunTime(chosenWorker) ?? 0)
       )
     } else {
       this.currentWorkerIndex =
-        this.pool.workers.length - 1 === this.currentWorkerIndex
+        this.currentWorkerIndex === this.pool.workers.length - 1
           ? 0
           : this.currentWorkerIndex + 1
       chosenWorker = this.pool.workers[this.currentWorkerIndex]