X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fpools%2Fselection-strategies%2Fleast-busy-worker-choice-strategy.ts;h=dabad6826568c38621c73d8fa4f6ac4efb28418f;hb=9b1068374b1a52479b07e1e22b692289d5579237;hp=b61bca1c8bdf450083474d8e2d8e78fef48ea2bc;hpb=8e5ca0401467b0a5c40b20a40ef08db6c05b9561;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 b61bca1c..dabad682 100644 --- a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts @@ -61,24 +61,31 @@ export class LeastBusyWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { + this.leastBusyNextWorkerNodeKey() + return this.nextWorkerNodeKey + } + + /** @inheritDoc */ + public remove (): boolean { + return true + } + + private leastBusyNextWorkerNodeKey (): void { 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.workerNodeReady(workerNodeKey) && workerTime === 0) { - this.nextWorkerNodeId = workerNodeKey + if (this.isWorkerNodeReady(workerNodeKey) && workerTime === 0) { + this.nextWorkerNodeKey = workerNodeKey break - } else if (this.workerNodeReady(workerNodeKey) && workerTime < minTime) { + } else if ( + this.isWorkerNodeReady(workerNodeKey) && + workerTime < minTime + ) { minTime = workerTime - this.nextWorkerNodeId = workerNodeKey + this.nextWorkerNodeKey = workerNodeKey } } - return this.nextWorkerNodeId - } - - /** @inheritDoc */ - public remove (): boolean { - return true } }