From: Jérôme Benoit Date: Tue, 27 Aug 2024 17:15:03 +0000 (+0200) Subject: refactor: cleanup worker node back pressure checks X-Git-Tag: v4.2.6~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=697d8c6debe324881015e70f43f708c6880be92a;p=poolifier.git refactor: cleanup worker node back pressure checks Signed-off-by: Jérôme Benoit --- 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 ), }),