From: Jérôme Benoit Date: Mon, 3 Apr 2023 21:38:29 +0000 (+0200) Subject: fix: ensure tasks are distributed equally at less used and less busy X-Git-Tag: v2.4.0-3~13 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=cf9c7b65548f4d3a4e95e87731ae1c40766d48fb;p=poolifier.git fix: ensure tasks are distributed equally at less used and less busy strategy startup Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts b/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts index f2e40162..e9ba619a 100644 --- a/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts @@ -30,7 +30,7 @@ export class LessBusyWorkerChoiceStrategy< let lessBusyWorkerKey!: number for (const [index, workerItem] of this.pool.workers.entries()) { const workerRunTime = workerItem.tasksUsage.runTime - if (!this.isDynamicPool && workerRunTime === 0) { + if (workerRunTime === 0) { return index } else if (workerRunTime < minRunTime) { minRunTime = workerRunTime 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 9cae4a54..f653160b 100644 --- a/src/pools/selection-strategies/less-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/less-used-worker-choice-strategy.ts @@ -25,7 +25,7 @@ export class LessUsedWorkerChoiceStrategy< for (const [index, workerItem] of this.pool.workers.entries()) { const tasksUsage = workerItem.tasksUsage const workerTasks = tasksUsage?.run + tasksUsage?.running - if (!this.isDynamicPool && workerTasks === 0) { + if (workerTasks === 0) { return index } else if (workerTasks < minNumberOfTasks) { minNumberOfTasks = workerTasks