X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fleast-used-worker-choice-strategy.ts;h=d20c32174cc553c01b120fdd055217218fc4c314;hb=7790a494fdff6a2152b3153d02c9fbe8de11ed93;hp=515b4e935db6e33fd5f3946c4f1b7cb0eb52a5f0;hpb=1079e6ed099b03189005b33702c1e9fa912c74d1;p=poolifier.git diff --git a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts index 515b4e93..d20c3217 100644 --- a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts @@ -42,8 +42,8 @@ export class LeastUsedWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number | undefined { - const chosenWorkerNodeKey = this.leastUsedNextWorkerNodeKey() - this.assignChosenWorkerNodeKey(chosenWorkerNodeKey) + this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey) + this.nextWorkerNodeKey = this.leastUsedNextWorkerNodeKey() return this.nextWorkerNodeKey } @@ -53,21 +53,18 @@ export class LeastUsedWorkerChoiceStrategy< } private leastUsedNextWorkerNodeKey (): number | undefined { - let minNumberOfTasks = Infinity let chosenWorkerNodeKey: number | undefined + let minNumberOfTasks = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerTaskStatistics = workerNode.usage.tasks const workerTasks = workerTaskStatistics.executed + workerTaskStatistics.executing + workerTaskStatistics.queued - if (this.isWorkerNodeEligible(workerNodeKey) && workerTasks === 0) { + if (workerTasks === 0) { chosenWorkerNodeKey = workerNodeKey break - } else if ( - this.isWorkerNodeEligible(workerNodeKey) && - workerTasks < minNumberOfTasks - ) { + } else if (workerTasks < minNumberOfTasks) { minNumberOfTasks = workerTasks chosenWorkerNodeKey = workerNodeKey }