X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fleast-busy-worker-choice-strategy.ts;h=0e8fdef31f27cdad48ba105554296f50df07f386;hb=516dcb0df1957823ec30f15db5f7585a7a302e8f;hp=14aee44f97a090f5270fa23d41389e32f0c5ee8d;hpb=f59e102739e13698f278f1d9d58ab26ed8150442;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..0e8fdef3 100644 --- a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts @@ -60,24 +60,32 @@ export class LeastBusyWorkerChoiceStrategy< } /** @inheritDoc */ - public choose (): number { + public choose (): number | undefined { + this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey) + this.nextWorkerNodeKey = this.leastBusyNextWorkerNodeKey() + return this.nextWorkerNodeKey + } + + /** @inheritDoc */ + public remove (): boolean { + return true + } + + private leastBusyNextWorkerNodeKey (): number | undefined { + let chosenWorkerNodeKey: number | undefined let minTime = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerTime = - workerNode.usage.runTime.aggregate + workerNode.usage.waitTime.aggregate + (workerNode.usage.runTime?.aggregate ?? 0) + + (workerNode.usage.waitTime?.aggregate ?? 0) if (workerTime === 0) { - this.nextWorkerNodeId = workerNodeKey + chosenWorkerNodeKey = workerNodeKey break } else if (workerTime < minTime) { minTime = workerTime - this.nextWorkerNodeId = workerNodeKey + chosenWorkerNodeKey = workerNodeKey } } - return this.nextWorkerNodeId - } - - /** @inheritDoc */ - public remove (): boolean { - return true + return chosenWorkerNodeKey } }