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=64f97d12e2027203715ee0129d036e1d2b42e2a2;hp=9ea64cb5a426bcccc0b3d1ddd8fc38de5612ee13;hpb=936fa0fb8e70b2c297938cc9455444486b6daa3e;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 9ea64cb5..0e8fdef3 100644 --- a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts @@ -7,7 +7,6 @@ import type { IWorker } from '../worker' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' import type { IWorkerChoiceStrategy, - StrategyPolicy, TaskStatisticsRequirements, WorkerChoiceStrategyOptions } from './selection-strategies-types' @@ -26,12 +25,6 @@ export class LeastBusyWorkerChoiceStrategy< > extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { - /** @inheritDoc */ - public readonly strategyPolicy: StrategyPolicy = { - dynamicWorkerUsage: false, - dynamicWorkerReady: true - } - /** @inheritDoc */ public readonly taskStatisticsRequirements: TaskStatisticsRequirements = { runTime: { @@ -68,8 +61,8 @@ export class LeastBusyWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number | undefined { - const chosenWorkerNodeKey = this.leastBusyNextWorkerNodeKey() - this.assignChosenWorkerNodeKey(chosenWorkerNodeKey) + this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey) + this.nextWorkerNodeKey = this.leastBusyNextWorkerNodeKey() return this.nextWorkerNodeKey } @@ -79,19 +72,16 @@ export class LeastBusyWorkerChoiceStrategy< } private leastBusyNextWorkerNodeKey (): number | undefined { - let minTime = Infinity let chosenWorkerNodeKey: number | undefined + 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.isWorkerNodeEligible(workerNodeKey) && workerTime === 0) { + if (workerTime === 0) { chosenWorkerNodeKey = workerNodeKey break - } else if ( - this.isWorkerNodeEligible(workerNodeKey) && - workerTime < minTime - ) { + } else if (workerTime < minTime) { minTime = workerTime chosenWorkerNodeKey = workerNodeKey }