refactor: add ELU statistics to pool information
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 11 May 2024 16:59:00 +0000 (18:59 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 11 May 2024 16:59:00 +0000 (18:59 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
CHANGELOG.md
src/pools/abstract-pool.ts
src/pools/pool.ts

index f774220521edcb652d8cdec1f9db424b4097f3b4..cd3ad0118783d6fc7c67d6f270aec524c8823061 100644 (file)
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+### Changed
+
+- Add ELU statistics to pool information.
+
 ## [4.0.6] - 2024-05-10
 
 ### Fixed
index d65ac2ffe7a92775e428e1a28ba8867a681ec136..e1042885e6d15d4e02c7f65d69c928561978ce18 100644 (file)
@@ -327,7 +327,7 @@ export abstract class AbstractPool<
         )
       }),
       busyWorkerNodes: this.workerNodes.reduce(
-        (accumulator, _workerNode, workerNodeKey) =>
+        (accumulator, _, workerNodeKey) =>
           this.isWorkerNodeBusy(workerNodeKey) ? accumulator + 1 : accumulator,
         0
       ),
@@ -455,6 +455,91 @@ export abstract class AbstractPool<
             )
           })
         }
+      }),
+      ...(this.workerChoiceStrategiesContext?.getTaskStatisticsRequirements()
+        .elu.aggregate === true && {
+        elu: {
+          idle: {
+            minimum: round(
+              min(
+                ...this.workerNodes.map(
+                  workerNode => workerNode.usage.elu.idle.minimum ?? Infinity
+                )
+              )
+            ),
+            maximum: round(
+              max(
+                ...this.workerNodes.map(
+                  workerNode => workerNode.usage.elu.idle.maximum ?? -Infinity
+                )
+              )
+            ),
+            ...(this.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
+              .elu.average && {
+              average: round(
+                average(
+                  this.workerNodes.reduce<number[]>(
+                    (accumulator, workerNode) =>
+                      accumulator.concat(workerNode.usage.elu.idle.history),
+                    []
+                  )
+                )
+              )
+            }),
+            ...(this.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
+              .elu.median && {
+              median: round(
+                median(
+                  this.workerNodes.reduce<number[]>(
+                    (accumulator, workerNode) =>
+                      accumulator.concat(workerNode.usage.elu.idle.history),
+                    []
+                  )
+                )
+              )
+            })
+          },
+          active: {
+            minimum: round(
+              min(
+                ...this.workerNodes.map(
+                  workerNode => workerNode.usage.elu.active.minimum ?? Infinity
+                )
+              )
+            ),
+            maximum: round(
+              max(
+                ...this.workerNodes.map(
+                  workerNode => workerNode.usage.elu.active.maximum ?? -Infinity
+                )
+              )
+            ),
+            ...(this.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
+              .elu.average && {
+              average: round(
+                average(
+                  this.workerNodes.reduce<number[]>(
+                    (accumulator, workerNode) =>
+                      accumulator.concat(workerNode.usage.elu.active.history),
+                    []
+                  )
+                )
+              )
+            }),
+            ...(this.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
+              .elu.median && {
+              median: round(
+                median(
+                  this.workerNodes.reduce<number[]>(
+                    (accumulator, workerNode) =>
+                      accumulator.concat(workerNode.usage.elu.active.history),
+                    []
+                  )
+                )
+              )
+            })
+          }
+        }
       })
     }
   }
@@ -1115,7 +1200,7 @@ export abstract class AbstractPool<
     }
     this.destroying = true
     await Promise.all(
-      this.workerNodes.map(async (_workerNode, workerNodeKey) => {
+      this.workerNodes.map(async (_, workerNodeKey) => {
         await this.destroyWorkerNode(workerNodeKey)
       })
     )
index 67409eea7afd3984e07ac2b15fa351fab1143244..a3552e486ed348fe8c0a35041a9ede5e3b028e92 100644 (file)
@@ -113,6 +113,20 @@ export interface PoolInfo {
     readonly average?: number
     readonly median?: number
   }
+  readonly elu?: {
+    idle: {
+      readonly minimum: number
+      readonly maximum: number
+      readonly average?: number
+      readonly median?: number
+    }
+    active: {
+      readonly minimum: number
+      readonly maximum: number
+      readonly average?: number
+      readonly median?: number
+    }
+  }
 }
 
 /**