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=14aee44f97a090f5270fa23d41389e32f0c5ee8d;hpb=465b29401ecddad49070d3b0df4e55dc3902788c;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 14aee44f..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,23 +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 + workerNode.usage.waitTime.aggregate - if (workerTime === 0) { - this.nextWorkerNodeId = workerNodeKey + (workerNode.usage.runTime?.aggregate ?? 0) + + (workerNode.usage.waitTime?.aggregate ?? 0) + if (this.isWorkerNodeReady(workerNodeKey) && workerTime === 0) { + this.nextWorkerNodeKey = workerNodeKey break - } else if (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 } }