refactor: add dynamic worker nodes count to pool info
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 8 Sep 2024 15:49:39 +0000 (17:49 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 8 Sep 2024 15:49:39 +0000 (17:49 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/abstract-pool.ts
src/pools/pool.ts
tests/pools/abstract-pool.test.mjs

index 91536f5e94d64ab16ef845d946dec4859cb44bf0..7bbdb8ac2b3fa23d09de50be2924b6c8ce17d8a7 100644 (file)
@@ -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(
index dac342ec8cbe3fa9feb77bc681b7a59794c30c54..74ceb0e34428858708ce0f5e6a9de8df1855ec35 100644 (file)
@@ -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
index 63162e3ae5fa8b3c5910f2b1e76ab57f4fdaa1fd..777fff9f62574be885052bcce2e3d7b2f6215837 100644 (file)
@@ -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),