X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fleast-used-worker-choice-strategy.ts;h=a505e6270aea7f19c458d1872aa2f69fe6b190cb;hb=e5536a06df85c554b8832f5fb5195b369258053b;hp=528bca1dc683adf0ac25cdd8f53ba4a2737b2294;hpb=8d1e1b3b417d37460c091ec8db3ac862201a244e;p=poolifier.git diff --git a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts index 528bca1d..a505e627 100644 --- a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts @@ -27,7 +27,7 @@ export class LeastUsedWorkerChoiceStrategy< opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS ) { super(pool, opts) - this.setTaskStatistics(this.opts) + this.setTaskStatisticsRequirements(this.opts) } /** @inheritDoc */ @@ -37,17 +37,7 @@ export class LeastUsedWorkerChoiceStrategy< /** @inheritDoc */ public update (): boolean { - return true - } - - /** @inheritDoc */ - public choose (): number { - const freeWorkerNodeKey = this.findFreeWorkerNodeKey() - if (freeWorkerNodeKey !== -1) { - return freeWorkerNodeKey - } let minNumberOfTasks = Infinity - let leastUsedWorkerNodeKey!: number for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerTaskStatistics = workerNode.workerUsage.tasks const workerTasks = @@ -55,13 +45,19 @@ export class LeastUsedWorkerChoiceStrategy< workerTaskStatistics.executing + workerTaskStatistics.queued if (workerTasks === 0) { - return workerNodeKey + this.nextWorkerNodeId = workerNodeKey + return true } else if (workerTasks < minNumberOfTasks) { minNumberOfTasks = workerTasks - leastUsedWorkerNodeKey = workerNodeKey + this.nextWorkerNodeId = workerNodeKey } } - return leastUsedWorkerNodeKey + return true + } + + /** @inheritDoc */ + public choose (): number { + return this.nextWorkerNodeId } /** @inheritDoc */