From: Jérôme Benoit Date: Sat, 11 May 2024 16:59:00 +0000 (+0200) Subject: refactor: add ELU statistics to pool information X-Git-Tag: v4.0.7~10 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=533a8e2293c1e3d4da47ee556873274a534b08fd;p=poolifier.git refactor: add ELU statistics to pool information Signed-off-by: Jérôme Benoit --- 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 + } + } } /**