X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fless-used-worker-choice-strategy.ts;h=1503e057ef42fc3890eb0e8cfbc33496a1dd9f5e;hb=d8728beaa590af2bfcb50502ef47546bcc6cb910;hp=1138df952a4600b31ff4f60a5540b94f035b31b3;hpb=2fc5cae38554901a21435ef087036a062c9d1632;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 1138df95..1503e057 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(opts) + this.checkOptions(this.opts) } /** @inheritDoc */ @@ -37,20 +37,20 @@ export class LessUsedWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { - const freeWorkerNodeKey = this.pool.findFreeWorkerNodeKey() + const freeWorkerNodeKey = this.findFreeWorkerNodeKey() if (freeWorkerNodeKey !== -1) { return freeWorkerNodeKey } 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