X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fless-used-worker-choice-strategy.ts;h=a8daa7b9f43d05e871cf38e0822cb986ba671239;hb=de037b034ea2cbc5530d45dd24685fde95a66155;hp=e3c395f477e4adb1d8a042ca71317c84111aae60;hpb=cb70b19deb97dc2c8ad1a769e59e870ee37f8e4d;p=poolifier.git diff --git a/src/pools/selection-strategies/less-used-worker-choice-strategy.ts b/src/pools/selection-strategies/less-used-worker-choice-strategy.ts index e3c395f4..a8daa7b9 100644 --- a/src/pools/selection-strategies/less-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/less-used-worker-choice-strategy.ts @@ -27,7 +27,7 @@ export class LessUsedWorkerChoiceStrategy< opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS ) { super(pool, opts) - this.checkOptions(this.opts) + this.setRequiredStatistics(this.opts) } /** @inheritDoc */ @@ -35,6 +35,11 @@ export class LessUsedWorkerChoiceStrategy< return true } + /** @inheritDoc */ + public update (): boolean { + return true + } + /** @inheritDoc */ public choose (): number { const freeWorkerNodeKey = this.findFreeWorkerNodeKey() @@ -43,21 +48,21 @@ export class LessUsedWorkerChoiceStrategy< } let minNumberOfTasks = Infinity let lessUsedWorkerNodeKey!: number - for (const [index, workerNode] of this.pool.workerNodes.entries()) { + for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const tasksUsage = workerNode.tasksUsage const workerTasks = tasksUsage.run + tasksUsage.running if (workerTasks === 0) { - return index + return workerNodeKey } else if (workerTasks < minNumberOfTasks) { minNumberOfTasks = workerTasks - lessUsedWorkerNodeKey = index + lessUsedWorkerNodeKey = workerNodeKey } } return lessUsedWorkerNodeKey } /** @inheritDoc */ - public remove (workerNodeKey: number): boolean { + public remove (): boolean { return true } }