From 8c7a518dde490c0d370dff2e47ee86062d715dad Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 19 Aug 2024 14:38:22 +0200 Subject: [PATCH] refactor: display back pressured worker nodes in pool info 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 | 27 +++++++++++++++++---------- src/pools/pool.ts | 6 ++++-- tests/pools/abstract-pool.test.mjs | 3 ++- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index a65cbbbc..cd55b7ff 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -311,16 +311,6 @@ export abstract class AbstractPool< utilization: round(this.utilization), }), workerNodes: this.workerNodes.length, - ...(this.opts.enableTasksQueue === true && { - stealingWorkerNodes: this.workerNodes.reduce( - (accumulator, workerNode) => - workerNode.info.continuousStealing || - workerNode.info.backPressureStealing - ? accumulator + 1 - : accumulator, - 0 - ), - }), idleWorkerNodes: this.workerNodes.reduce( (accumulator, _, workerNodeKey) => this.isWorkerNodeIdle(workerNodeKey) ? accumulator + 1 : accumulator, @@ -331,6 +321,23 @@ export abstract class AbstractPool< this.isWorkerNodeBusy(workerNodeKey) ? accumulator + 1 : accumulator, 0 ), + ...(this.opts.enableTasksQueue === true && { + stealingWorkerNodes: this.workerNodes.reduce( + (accumulator, workerNode) => + workerNode.info.continuousStealing || + workerNode.info.backPressureStealing + ? accumulator + 1 + : accumulator, + 0 + ), + }), + ...(this.opts.enableTasksQueue === true && { + backPressureWorkerNodes: this.workerNodes.reduce( + (accumulator, workerNode) => + workerNode.info.backPressure ? accumulator + 1 : accumulator, + 0 + ), + }), executedTasks: this.workerNodes.reduce( (accumulator, workerNode) => accumulator + workerNode.usage.tasks.executed, diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 27d897b2..b6c343bb 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -88,12 +88,14 @@ export interface PoolInfo { readonly utilization?: number /** Pool total worker nodes. */ readonly workerNodes: number - /** Pool tasks stealing worker nodes. */ - readonly stealingWorkerNodes?: number /** Pool idle worker nodes. */ readonly idleWorkerNodes: number /** Pool busy worker nodes. */ readonly busyWorkerNodes: number + /** Pool tasks stealing worker nodes. */ + readonly stealingWorkerNodes?: number + /** Pool tasks back pressure worker nodes. */ + readonly backPressureWorkerNodes?: number readonly executedTasks: number readonly executingTasks: number readonly queuedTasks?: number diff --git a/tests/pools/abstract-pool.test.mjs b/tests/pools/abstract-pool.test.mjs index 5b4f0246..ed4543dd 100644 --- a/tests/pools/abstract-pool.test.mjs +++ b/tests/pools/abstract-pool.test.mjs @@ -1263,9 +1263,10 @@ describe('Abstract pool test suite', () => { minSize: expect.any(Number), maxSize: expect.any(Number), workerNodes: expect.any(Number), - stealingWorkerNodes: expect.any(Number), idleWorkerNodes: expect.any(Number), busyWorkerNodes: expect.any(Number), + stealingWorkerNodes: expect.any(Number), + backPressureWorkerNodes: expect.any(Number), executedTasks: expect.any(Number), executingTasks: expect.any(Number), maxQueuedTasks: expect.any(Number), -- 2.34.1