From 533a8e2293c1e3d4da47ee556873274a534b08fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 11 May 2024 18:59:00 +0200 Subject: [PATCH] refactor: add ELU statistics to pool information MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 4 ++ src/pools/abstract-pool.ts | 89 +++++++++++++++++++++++++++++++++++++- src/pools/pool.ts | 14 ++++++ 3 files changed, 105 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7742205..cd3ad011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index d65ac2ff..e1042885 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -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( + (accumulator, workerNode) => + accumulator.concat(workerNode.usage.elu.idle.history), + [] + ) + ) + ) + }), + ...(this.workerChoiceStrategiesContext.getTaskStatisticsRequirements() + .elu.median && { + median: round( + median( + this.workerNodes.reduce( + (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( + (accumulator, workerNode) => + accumulator.concat(workerNode.usage.elu.active.history), + [] + ) + ) + ) + }), + ...(this.workerChoiceStrategiesContext.getTaskStatisticsRequirements() + .elu.median && { + median: round( + median( + this.workerNodes.reduce( + (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) }) ) diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 67409eea..a3552e48 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -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 + } + } } /** -- 2.34.1