From: Jérôme Benoit Date: Wed, 5 Jul 2023 23:06:49 +0000 (+0200) Subject: feat: add average and median to pool info runTime and waitTime X-Git-Tag: v2.6.9~7 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=98e72cda1ce363322fc7ae868b66dec89a1ad74c;p=poolifier.git feat: add average and median to pool info runTime and waitTime Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 5b6c1874..88f2c9e9 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -301,31 +301,83 @@ export abstract class AbstractPool< ...(this.workerChoiceStrategyContext.getTaskStatisticsRequirements() .runTime.aggregate && { runTime: { - minimum: Math.min( - ...this.workerNodes.map( - workerNode => workerNode.usage.runTime?.minimum ?? Infinity + minimum: round( + Math.min( + ...this.workerNodes.map( + workerNode => workerNode.usage.runTime?.minimum ?? Infinity + ) ) ), - maximum: Math.max( - ...this.workerNodes.map( - workerNode => workerNode.usage.runTime?.maximum ?? -Infinity + maximum: round( + Math.max( + ...this.workerNodes.map( + workerNode => workerNode.usage.runTime?.maximum ?? -Infinity + ) ) - ) + ), + average: round( + this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator + (workerNode.usage.runTime?.aggregate ?? 0), + 0 + ) / + this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator + (workerNode.usage.tasks?.executed ?? 0), + 0 + ) + ), + ...(this.workerChoiceStrategyContext.getTaskStatisticsRequirements() + .runTime.median && { + median: round( + median( + this.workerNodes.map( + workerNode => workerNode.usage.runTime?.median ?? 0 + ) + ) + ) + }) } }), ...(this.workerChoiceStrategyContext.getTaskStatisticsRequirements() .waitTime.aggregate && { waitTime: { - minimum: Math.min( - ...this.workerNodes.map( - workerNode => workerNode.usage.waitTime?.minimum ?? Infinity + minimum: round( + Math.min( + ...this.workerNodes.map( + workerNode => workerNode.usage.waitTime?.minimum ?? Infinity + ) ) ), - maximum: Math.max( - ...this.workerNodes.map( - workerNode => workerNode.usage.waitTime?.maximum ?? -Infinity + maximum: round( + Math.max( + ...this.workerNodes.map( + workerNode => workerNode.usage.waitTime?.maximum ?? -Infinity + ) ) - ) + ), + average: round( + this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator + (workerNode.usage.waitTime?.aggregate ?? 0), + 0 + ) / + this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator + (workerNode.usage.tasks?.executed ?? 0), + 0 + ) + ), + ...(this.workerChoiceStrategyContext.getTaskStatisticsRequirements() + .waitTime.median && { + median: round( + median( + this.workerNodes.map( + workerNode => workerNode.usage.waitTime?.median ?? 0 + ) + ) + ) + }) } }) } @@ -602,8 +654,9 @@ export abstract class AbstractPool< ): void { const workerTaskStatistics = workerUsage.tasks --workerTaskStatistics.executing - ++workerTaskStatistics.executed - if (message.taskError != null) { + if (message.taskError == null) { + ++workerTaskStatistics.executed + } else { ++workerTaskStatistics.failed } } @@ -633,8 +686,7 @@ export abstract class AbstractPool< workerUsage.tasks.executed !== 0 ) { workerUsage.runTime.average = - workerUsage.runTime.aggregate / - (workerUsage.tasks.executed - workerUsage.tasks.failed) + workerUsage.runTime.aggregate / workerUsage.tasks.executed } if ( this.workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime @@ -673,8 +725,7 @@ export abstract class AbstractPool< workerUsage.tasks.executed !== 0 ) { workerUsage.waitTime.average = - workerUsage.waitTime.aggregate / - (workerUsage.tasks.executed - workerUsage.tasks.failed) + workerUsage.waitTime.aggregate / workerUsage.tasks.executed } if ( this.workerChoiceStrategyContext.getTaskStatisticsRequirements() @@ -730,12 +781,10 @@ export abstract class AbstractPool< .average && workerUsage.tasks.executed !== 0 ) { - const executedTasks = - workerUsage.tasks.executed - workerUsage.tasks.failed workerUsage.elu.idle.average = - workerUsage.elu.idle.aggregate / executedTasks + workerUsage.elu.idle.aggregate / workerUsage.tasks.executed workerUsage.elu.active.average = - workerUsage.elu.active.aggregate / executedTasks + workerUsage.elu.active.aggregate / workerUsage.tasks.executed } if ( this.workerChoiceStrategyContext.getTaskStatisticsRequirements().elu diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 15654803..5be4f95a 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -89,10 +89,14 @@ export interface PoolInfo { runTime?: { minimum: number maximum: number + average: number + median?: number } waitTime?: { minimum: number maximum: number + average: number + median?: number } } diff --git a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts index cbe00a47..54d0e7cb 100644 --- a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts @@ -60,7 +60,7 @@ export class LeastEluWorkerChoiceStrategy< let minWorkerElu = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerUsage = workerNode.usage - const workerElu = workerUsage.elu?.active.aggregate ?? 0 + const workerElu = workerUsage.elu?.active?.aggregate ?? 0 if (workerElu === 0) { this.nextWorkerNodeId = workerNodeKey break