X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fleast-busy-worker-choice-strategy.ts;h=0e8fdef31f27cdad48ba105554296f50df07f386;hb=64f97d12e2027203715ee0129d036e1d2b42e2a2;hp=224ca540130f49c37e6b28d5de471e5237dddb14;hpb=bde3557b4daaacaea222926c3ac6934dcb90fdaa;p=poolifier.git diff --git a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts index 224ca540..0e8fdef3 100644 --- a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts @@ -61,8 +61,8 @@ export class LeastBusyWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number | undefined { - const chosenWorkerNodeKey = this.leastBusyNextWorkerNodeKey() - this.assignChosenWorkerNodeKey(chosenWorkerNodeKey) + this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey) + this.nextWorkerNodeKey = this.leastBusyNextWorkerNodeKey() return this.nextWorkerNodeKey } @@ -72,19 +72,16 @@ export class LeastBusyWorkerChoiceStrategy< } private leastBusyNextWorkerNodeKey (): number | undefined { - let minTime = Infinity let chosenWorkerNodeKey: number | undefined + let minTime = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerTime = (workerNode.usage.runTime?.aggregate ?? 0) + (workerNode.usage.waitTime?.aggregate ?? 0) - if (this.isWorkerNodeEligible(workerNodeKey) && workerTime === 0) { + if (workerTime === 0) { chosenWorkerNodeKey = workerNodeKey break - } else if ( - this.isWorkerNodeEligible(workerNodeKey) && - workerTime < minTime - ) { + } else if (workerTime < minTime) { minTime = workerTime chosenWorkerNodeKey = workerNodeKey }