From 0ebe2a9f266a9cfd426a5faec1743cb9cfe59ffd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 9 Apr 2023 19:02:53 +0200 Subject: [PATCH] perf: optimize runtime worker choice strategy change MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) 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. * -- 2.34.1