X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fleast-used-worker-choice-strategy.ts;h=d0adbcd7b77c4ef095f25fced318148498f42935;hb=9fe8fd698590c2494dc6793cfd8c08026fe88a31;hp=515b4e935db6e33fd5f3946c4f1b7cb0eb52a5f0;hpb=fd13902fd959335e2c0f95d1b464317a2da8b6cf;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..d0adbcd7 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,7 @@ export class LeastUsedWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number | undefined { - const chosenWorkerNodeKey = this.leastUsedNextWorkerNodeKey() - this.assignChosenWorkerNodeKey(chosenWorkerNodeKey) + this.nextWorkerNodeKey = this.leastUsedNextWorkerNodeKey() return this.nextWorkerNodeKey } @@ -56,18 +55,18 @@ export class LeastUsedWorkerChoiceStrategy< let minNumberOfTasks = Infinity let chosenWorkerNodeKey: number | undefined for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { + if (!this.isWorkerNodeEligible(workerNodeKey)) { + continue + } 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 }