From: Jérôme Benoit Date: Sun, 9 Apr 2023 17:02:53 +0000 (+0200) Subject: perf: optimize runtime worker choice strategy change X-Git-Tag: v2.4.6~13 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0ebe2a9f266a9cfd426a5faec1743cb9cfe59ffd;p=poolifier.git perf: optimize runtime worker choice strategy change Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index f4f3e833..41ce6aa0 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -191,21 +191,16 @@ export abstract class AbstractPool< ): void { this.checkValidWorkerChoiceStrategy(workerChoiceStrategy) this.opts.workerChoiceStrategy = workerChoiceStrategy - for (const [index, workerNode] of this.workerNodes.entries()) { - this.setWorkerNode( - index, - workerNode.worker, - { - run: 0, - running: 0, - runTime: 0, - runTimeHistory: new CircularArray(), - avgRunTime: 0, - medRunTime: 0, - error: 0 - }, - workerNode.tasksQueue - ) + for (const workerNode of this.workerNodes) { + this.setWorkerNodeTasksUsage(workerNode, { + run: 0, + running: 0, + runTime: 0, + runTimeHistory: new CircularArray(), + avgRunTime: 0, + medRunTime: 0, + error: 0 + }) } this.workerChoiceStrategyContext.setWorkerChoiceStrategy( workerChoiceStrategy @@ -482,6 +477,19 @@ export abstract class AbstractPool< } } + /** + * Sets the given worker node its tasks usage in the pool. + * + * @param workerNode - The worker node. + * @param tasksUsage - The worker node tasks usage. + */ + private setWorkerNodeTasksUsage ( + workerNode: WorkerNode, + tasksUsage: TasksUsage + ): void { + workerNode.tasksUsage = tasksUsage + } + /** * Gets the given worker its tasks usage in the pool. *