From: Jérôme Benoit Date: Thu, 24 Aug 2023 18:00:43 +0000 (+0200) Subject: fix: fix pool information median computation X-Git-Tag: v2.6.35~23 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3baa083708b113152d769123eb87ef8d3c3a7ce7;p=poolifier.git fix: fix pool information median computation Signed-off-by: Jérôme Benoit --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 811b8397..0e8866ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Don't account worker usage statistics for tasks that have failed. +- Fix pool information runtime and wait time median computation. ### Changed diff --git a/docs/worker-choice-strategies.md b/docs/worker-choice-strategies.md index 296d8c3b..a2b035f7 100644 --- a/docs/worker-choice-strategies.md +++ b/docs/worker-choice-strategies.md @@ -34,4 +34,4 @@ Worker choice strategies enable only the statistics that are needed to choose th ### Simple moving median -Strategies using the average task execution time for each worker can use the simple moving median instead. Simple moving median is more robust to outliers and can be used to avoid assigning tasks to workers that are currently overloaded. Simple moving median usage introduces a small overhead: measurement history must be kept for each worker and the simple moving median must be recomputed each time a task has finished. +Strategies using the simple moving average task execution time for each worker can use the simple moving median instead. Simple moving median is more robust to outliers and can be used to avoid assigning tasks to workers that are currently overloaded. diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index a11a5741..8c202696 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -427,21 +427,26 @@ export abstract class AbstractPool< ) ) ), - average: round( - average( - this.workerNodes.reduce( - (accumulator, workerNode) => - accumulator.concat(workerNode.usage.runTime.history), - [] + ...(this.workerChoiceStrategyContext.getTaskStatisticsRequirements() + .runTime.average && { + average: round( + average( + this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator.concat(workerNode.usage.runTime.history), + [] + ) ) ) - ), + }), ...(this.workerChoiceStrategyContext.getTaskStatisticsRequirements() .runTime.median && { median: round( median( - this.workerNodes.map( - (workerNode) => workerNode.usage.runTime?.median ?? 0 + this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator.concat(workerNode.usage.runTime.history), + [] ) ) ) @@ -465,21 +470,26 @@ export abstract class AbstractPool< ) ) ), - average: round( - average( - this.workerNodes.reduce( - (accumulator, workerNode) => - accumulator.concat(workerNode.usage.waitTime.history), - [] + ...(this.workerChoiceStrategyContext.getTaskStatisticsRequirements() + .waitTime.average && { + average: round( + average( + this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator.concat(workerNode.usage.waitTime.history), + [] + ) ) ) - ), + }), ...(this.workerChoiceStrategyContext.getTaskStatisticsRequirements() .waitTime.median && { median: round( median( - this.workerNodes.map( - (workerNode) => workerNode.usage.waitTime?.median ?? 0 + this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator.concat(workerNode.usage.waitTime.history), + [] ) ) ) diff --git a/src/pools/pool.ts b/src/pools/pool.ts index fb59d37a..7b549809 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -84,13 +84,13 @@ export interface PoolInfo { readonly runTime?: { readonly minimum: number readonly maximum: number - readonly average: number + readonly average?: number readonly median?: number } readonly waitTime?: { readonly minimum: number readonly maximum: number - readonly average: number + readonly average?: number readonly median?: number } }