X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fweighted-round-robin-worker-choice-strategy.ts;h=a0553fcb81ace9c910b1ecd755b9c123b640f362;hb=f6b641d651fdd5114bcd63bf1c991955d5b7d3eb;hp=1817394933978fcc9a18a4052dcec1c44efe5201;hpb=138d29a820e8a61d10ba03fe42c5d77596ef788c;p=poolifier.git diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index 18173949..a0553fcb 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -50,7 +50,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy< opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS ) { super(pool, opts) - this.checkOptions(this.opts) + this.setRequiredStatistics(this.opts) this.defaultWorkerWeight = this.computeDefaultWorkerWeight() } @@ -75,7 +75,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy< if (workerVirtualTaskRunTime < workerWeight) { this.workerVirtualTaskRunTime = workerVirtualTaskRunTime + - this.getWorkerVirtualTaskRunTime(chosenWorkerNodeKey) + this.getWorkerTaskRunTime(chosenWorkerNodeKey) } else { this.currentWorkerNodeId = this.currentWorkerNodeId === this.pool.workerNodes.length - 1 @@ -91,23 +91,14 @@ export class WeightedRoundRobinWorkerChoiceStrategy< if (this.currentWorkerNodeId === workerNodeKey) { if (this.pool.workerNodes.length === 0) { this.currentWorkerNodeId = 0 - } else { - this.currentWorkerNodeId = - this.currentWorkerNodeId > this.pool.workerNodes.length - 1 - ? this.pool.workerNodes.length - 1 - : this.currentWorkerNodeId + } else if (this.currentWorkerNodeId > this.pool.workerNodes.length - 1) { + this.currentWorkerNodeId = this.pool.workerNodes.length - 1 } this.workerVirtualTaskRunTime = 0 } return true } - private getWorkerVirtualTaskRunTime (workerNodeKey: number): number { - return this.requiredStatistics.medRunTime - ? this.pool.workerNodes[workerNodeKey].tasksUsage.medRunTime - : this.pool.workerNodes[workerNodeKey].tasksUsage.avgRunTime - } - private computeDefaultWorkerWeight (): number { let cpusCycleTimeWeight = 0 for (const cpu of cpus()) {