X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fleast-busy-worker-choice-strategy.ts;h=3c0856856189ab7d7af4c4f2a625ae9058ac9029;hb=96cd253f81dfa150fe5e40d81143849c97ffc12f;hp=2dfb6083d4d85e6a4fe9b58d5a2eddca07e55819;hpb=8d20e449d72975f6add9177d1097d5a204d14f71;p=poolifier.git diff --git a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts index 2dfb6083..3c085685 100644 --- a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts @@ -4,7 +4,7 @@ import type { IWorker } from '../worker' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' import type { IWorkerChoiceStrategy, - RequiredStatistics, + TaskStatisticsRequirements, WorkerChoiceStrategyOptions } from './selection-strategies-types' @@ -23,11 +23,11 @@ export class LeastBusyWorkerChoiceStrategy< extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { /** @inheritDoc */ - public readonly requiredStatistics: RequiredStatistics = { + public readonly taskStatisticsRequirements: TaskStatisticsRequirements = { runTime: true, avgRunTime: false, medRunTime: false, - waitTime: false, + waitTime: true, avgWaitTime: false, medWaitTime: false, elu: false @@ -39,7 +39,7 @@ export class LeastBusyWorkerChoiceStrategy< opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS ) { super(pool, opts) - this.setRequiredStatistics(this.opts) + this.setTaskStatistics(this.opts) } /** @inheritDoc */ @@ -54,18 +54,16 @@ export class LeastBusyWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { - const freeWorkerNodeKey = this.findFreeWorkerNodeKey() - if (freeWorkerNodeKey !== -1) { - return freeWorkerNodeKey - } - let minRunTime = Infinity + let minTime = Infinity let leastBusyWorkerNodeKey!: number for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { - const workerRunTime = workerNode.tasksUsage.runTime - if (workerRunTime === 0) { + const workerTime = + workerNode.workerUsage.runTime.aggregation + + workerNode.workerUsage.waitTime.aggregation + if (workerTime === 0) { return workerNodeKey - } else if (workerRunTime < minRunTime) { - minRunTime = workerRunTime + } else if (workerTime < minTime) { + minTime = workerTime leastBusyWorkerNodeKey = workerNodeKey } }