From 697d8c6debe324881015e70f43f708c6880be92a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 27 Aug 2024 19:15:03 +0200 Subject: [PATCH] refactor: cleanup worker node back pressure checks 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 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index b3b1623f..2cf21126 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -812,10 +812,9 @@ export abstract class AbstractPool< */ protected internalBackPressure (): boolean { return ( - this.opts.enableTasksQueue === true && this.workerNodes.reduce( - (accumulator, workerNode) => - workerNode.info.ready && workerNode.info.backPressure + (accumulator, _, workerNodeKey) => + this.isWorkerNodeBackPressured(workerNodeKey) ? accumulator + 1 : accumulator, 0 @@ -1333,6 +1332,11 @@ export abstract class AbstractPool< }) } + private isWorkerNodeBackPressured (workerNodeKey: number): boolean { + const workerNode = this.workerNodes[workerNodeKey] + return workerNode.info.ready && workerNode.info.backPressure + } + private isWorkerNodeBusy (workerNodeKey: number): boolean { const workerNode = this.workerNodes[workerNodeKey] if (this.opts.enableTasksQueue === true) { @@ -2073,8 +2077,10 @@ export abstract class AbstractPool< }), ...(this.opts.enableTasksQueue === true && { backPressureWorkerNodes: this.workerNodes.reduce( - (accumulator, workerNode) => - workerNode.info.backPressure ? accumulator + 1 : accumulator, + (accumulator, _, workerNodeKey) => + this.isWorkerNodeBackPressured(workerNodeKey) + ? accumulator + 1 + : accumulator, 0 ), }), -- 2.34.1