From: Jérôme Benoit Date: Wed, 19 Jul 2023 10:05:41 +0000 (+0200) Subject: refactor: cleanup measurement statistics computation code X-Git-Tag: v2.6.18~6 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=008512c74c553d4400f3fabb46053e5e8a4a0cd1;p=poolifier.git refactor: cleanup measurement statistics computation code Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 6467f4eb..5481099f 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -36,6 +36,7 @@ import type { WorkerUsage } from './worker' import { + type MeasurementStatisticsRequirements, Measurements, WorkerChoiceStrategies, type WorkerChoiceStrategy, @@ -774,22 +775,21 @@ export abstract class AbstractPool< workerUsage: WorkerUsage, message: MessageValue ): void { + const eluTaskStatisticsRequirements: MeasurementStatisticsRequirements = + this.workerChoiceStrategyContext.getTaskStatisticsRequirements().elu updateMeasurementStatistics( workerUsage.elu.active, - this.workerChoiceStrategyContext.getTaskStatisticsRequirements().elu, + eluTaskStatisticsRequirements, message.taskPerformance?.elu?.active ?? 0, workerUsage.tasks.executed ) updateMeasurementStatistics( workerUsage.elu.idle, - this.workerChoiceStrategyContext.getTaskStatisticsRequirements().elu, + eluTaskStatisticsRequirements, message.taskPerformance?.elu?.idle ?? 0, workerUsage.tasks.executed ) - if ( - this.workerChoiceStrategyContext.getTaskStatisticsRequirements().elu - .aggregate - ) { + if (eluTaskStatisticsRequirements.aggregate) { if (message.taskPerformance?.elu != null) { if (workerUsage.elu.utilization != null) { workerUsage.elu.utilization = diff --git a/src/utils.ts b/src/utils.ts index cc71491a..45e4fd23 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -136,13 +136,13 @@ export const isAsyncFunction = ( * @param measurementStatistics - The measurement statistics to update. * @param measurementRequirements - The measurement statistics requirements. * @param measurementValue - The measurement value. - * @param tasksExecuted - The number of tasks executed. + * @param numberOfMeasurements - The number of measurements. */ export const updateMeasurementStatistics = ( measurementStatistics: MeasurementStatistics, measurementRequirements: MeasurementStatisticsRequirements, measurementValue: number, - tasksExecuted: number + numberOfMeasurements: number ): void => { if (measurementRequirements.aggregate) { measurementStatistics.aggregate = @@ -155,9 +155,9 @@ export const updateMeasurementStatistics = ( measurementValue, measurementStatistics.maximum ?? -Infinity ) - if (measurementRequirements.average && tasksExecuted !== 0) { + if (measurementRequirements.average && numberOfMeasurements !== 0) { measurementStatistics.average = - measurementStatistics.aggregate / tasksExecuted + measurementStatistics.aggregate / numberOfMeasurements } if (measurementRequirements.median && measurementValue != null) { measurementStatistics.history.push(measurementValue)