X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fleast-busy-worker-choice-strategy.ts;h=9a1550e06f60dfecc4339f56ac2c01ad3a7344cf;hb=3d76750ac8dacd95003ca89cf9542c3b2a014b8c;hp=b61bca1c8bdf450083474d8e2d8e78fef48ea2bc;hpb=19dbc45b0e2975f938aaae8274902ebe82c48cad;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..9a1550e0 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 { + return this.leastBusyNextWorkerNodeKey() + } + + /** @inheritDoc */ + public remove (): boolean { + return true + } + + private leastBusyNextWorkerNodeKey (): number { 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 + return this.nextWorkerNodeKey } }