WRR strategy: round the default weight computation
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 11 Oct 2022 08:57:48 +0000 (10:57 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 11 Oct 2022 08:57:48 +0000 (10:57 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts

index e05b6fae22a9e35ddb702165c779e7e3ae319635..ed8690918f6177656020d84a915f11de85023aca 100644 (file)
@@ -87,11 +87,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
     } else {
       this.setWorkerTaskRunTime(currentWorker, workerTaskWeight, 0)
     }
-    if (
-      workerVirtualTaskRunTime <
-      (this.workersTaskRunTime.get(currentWorker)?.weight ??
-        this.defaultWorkerWeight)
-    ) {
+    if (workerVirtualTaskRunTime < workerTaskWeight) {
       this.previousWorkerIndex = this.currentWorkerIndex
     } else {
       this.previousWorkerIndex = this.currentWorkerIndex
@@ -136,6 +132,6 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
       const cpuCycleTime = 1 / (cpu.speed / Math.pow(10, numberOfDigit))
       cpusCycleTimeWeight += cpuCycleTime * Math.pow(10, numberOfDigit)
     }
-    return cpusCycleTimeWeight / cpus().length
+    return Math.round(cpusCycleTimeWeight / cpus().length)
   }
 }