From: Jérôme Benoit Date: Mon, 3 Apr 2023 23:32:38 +0000 (+0200) Subject: perf: pickup free worker in the less busy and used strategies for fixed X-Git-Tag: v2.4.0-3~4 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c141008c44abbc291b45355aa5b8fef5d3ba1de7;p=poolifier.git perf: pickup free worker in the less busy and used strategies for fixed pool 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 e9ba619a..61e2d369 100644 --- a/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts @@ -26,6 +26,10 @@ export class LessBusyWorkerChoiceStrategy< /** {@inheritDoc} */ public choose (): number { + const freeWorkerKey = this.pool.findFreeWorkerKey() + if (!this.isDynamicPool && freeWorkerKey !== false) { + return freeWorkerKey + } let minRunTime = Infinity let lessBusyWorkerKey!: number for (const [index, workerItem] of this.pool.workers.entries()) { 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 f653160b..7fe56ef9 100644 --- a/src/pools/selection-strategies/less-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/less-used-worker-choice-strategy.ts @@ -20,6 +20,10 @@ export class LessUsedWorkerChoiceStrategy< /** {@inheritDoc} */ public choose (): number { + const freeWorkerKey = this.pool.findFreeWorkerKey() + if (!this.isDynamicPool && freeWorkerKey !== false) { + return freeWorkerKey + } let minNumberOfTasks = Infinity let lessUsedWorkerKey!: number for (const [index, workerItem] of this.pool.workers.entries()) {