X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fleast-used-worker-choice-strategy.ts;h=aaa6c21dc0f3dc7654a4b4d7986d44f809ef96b0;hb=2c039e4373e86714cdf27e77440b12ee8eb2e4db;hp=85e145a041b7868bc96565091a0beec16b7b6d89;hpb=5a5fc090d6f7eb9248df1ba5c0ff4d001461b6d4;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 85e145a0..aaa6c21d 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.setRequiredStatistics(this.opts) + this.setTaskStatisticsRequirements(this.opts) } /** @inheritDoc */ @@ -42,23 +42,22 @@ export class LeastUsedWorkerChoiceStrategy< /** @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 tasksUsage = workerNode.tasksUsage - const workerTasks = tasksUsage.run + tasksUsage.running + const workerTaskStatistics = workerNode.workerUsage.tasks + const workerTasks = + workerTaskStatistics.executed + + workerTaskStatistics.executing + + workerTaskStatistics.queued if (workerTasks === 0) { - return workerNodeKey + this.nextWorkerNodeId = workerNodeKey + break } else if (workerTasks < minNumberOfTasks) { minNumberOfTasks = workerTasks - leastUsedWorkerNodeKey = workerNodeKey + this.nextWorkerNodeId = workerNodeKey } } - return leastUsedWorkerNodeKey + return this.nextWorkerNodeId } /** @inheritDoc */