From: Jérôme Benoit Date: Sun, 8 Sep 2024 15:49:39 +0000 (+0200) Subject: refactor: add dynamic worker nodes count to pool info X-Git-Tag: v4.2.11~8 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=01277ce688c015fff1bee425276b20077e7a8f34;p=poolifier.git refactor: add dynamic worker nodes count to pool info Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 91536f5e..7bbdb8ac 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -2063,6 +2063,13 @@ export abstract class AbstractPool< 0 ), workerNodes: this.workerNodes.length, + ...(this.type === PoolTypes.dynamic && { + dynamicWorkerNodes: this.workerNodes.reduce( + (accumulator, workerNode) => + workerNode.info.dynamic ? accumulator + 1 : accumulator, + 0 + ), + }), ...(this.opts.enableTasksQueue === true && { backPressure: this.backPressure, backPressureWorkerNodes: this.workerNodes.reduce( diff --git a/src/pools/pool.ts b/src/pools/pool.ts index dac342ec..74ceb0e3 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -87,6 +87,8 @@ export interface PoolInfo { /** Pool busy worker nodes. */ readonly busyWorkerNodes: number readonly defaultStrategy: WorkerChoiceStrategy + /** Pool dynamic worker nodes. */ + readonly dynamicWorkerNodes?: number readonly elu?: { active: { readonly average?: number diff --git a/tests/pools/abstract-pool.test.mjs b/tests/pools/abstract-pool.test.mjs index 63162e3a..777fff9f 100644 --- a/tests/pools/abstract-pool.test.mjs +++ b/tests/pools/abstract-pool.test.mjs @@ -773,6 +773,7 @@ describe('Abstract pool test suite', () => { expect(pool.info).toStrictEqual({ busyWorkerNodes: 0, defaultStrategy: WorkerChoiceStrategies.ROUND_ROBIN, + dynamicWorkerNodes: 0, executedTasks: 0, executingTasks: 0, failedTasks: 0, @@ -1130,12 +1131,13 @@ describe('Abstract pool test suite', () => { expect(pool.emitter.eventNames()).toStrictEqual([PoolEvents.ready]) expect(poolReady).toBe(1) expect(poolInfo).toStrictEqual({ - busyWorkerNodes: expect.any(Number), + busyWorkerNodes: 0, defaultStrategy: WorkerChoiceStrategies.ROUND_ROBIN, - executedTasks: expect.any(Number), - executingTasks: expect.any(Number), - failedTasks: expect.any(Number), - idleWorkerNodes: expect.any(Number), + dynamicWorkerNodes: 0, + executedTasks: 0, + executingTasks: 0, + failedTasks: 0, + idleWorkerNodes: Math.floor(numberOfWorkers / 2), maxSize: numberOfWorkers, minSize: Math.floor(numberOfWorkers / 2), ready: true, @@ -1248,6 +1250,7 @@ describe('Abstract pool test suite', () => { expect(poolFullInfo).toStrictEqual({ busyWorkerNodes: expect.any(Number), defaultStrategy: WorkerChoiceStrategies.ROUND_ROBIN, + dynamicWorkerNodes: Math.floor(numberOfWorkers / 2), executedTasks: expect.any(Number), executingTasks: expect.any(Number), failedTasks: expect.any(Number), @@ -1267,6 +1270,7 @@ describe('Abstract pool test suite', () => { expect(poolFullEndInfo).toStrictEqual({ busyWorkerNodes: expect.any(Number), defaultStrategy: WorkerChoiceStrategies.ROUND_ROBIN, + dynamicWorkerNodes: 0, executedTasks: expect.any(Number), executingTasks: expect.any(Number), failedTasks: expect.any(Number), @@ -1392,6 +1396,7 @@ describe('Abstract pool test suite', () => { expect(poolInfo).toStrictEqual({ busyWorkerNodes: 0, defaultStrategy: WorkerChoiceStrategies.ROUND_ROBIN, + dynamicWorkerNodes: 0, executedTasks: expect.any(Number), executingTasks: expect.any(Number), failedTasks: expect.any(Number),