X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fleast-busy-worker-choice-strategy.ts;h=8afd2c36edda1bcb7fe94dcb2b6d1f51c36eac9e;hb=932fc8be063cc15b543ad14c2ab6df0fa4224fba;hp=67332c70c4b21a895e97a3fa037526b5da57bc33;hpb=272d4d8fda8b9607fde68d57ec5b145639f94514;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 67332c70..8afd2c36 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, - TaskStatistics, + TaskStatisticsRequirements, WorkerChoiceStrategyOptions } from './selection-strategies-types' @@ -23,13 +23,17 @@ export class LeastBusyWorkerChoiceStrategy< extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { /** @inheritDoc */ - public readonly taskStatistics: TaskStatistics = { - runTime: true, - avgRunTime: false, - medRunTime: false, - waitTime: false, - avgWaitTime: false, - medWaitTime: false, + public readonly taskStatisticsRequirements: TaskStatisticsRequirements = { + runTime: { + aggregate: true, + average: false, + median: false + }, + waitTime: { + aggregate: true, + average: false, + median: false + }, elu: false } @@ -39,7 +43,7 @@ export class LeastBusyWorkerChoiceStrategy< opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS ) { super(pool, opts) - this.setTaskStatistics(this.opts) + this.setTaskStatisticsRequirements(this.opts) } /** @inheritDoc */ @@ -54,18 +58,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.aggregate + + workerNode.workerUsage.waitTime.aggregate + if (workerTime === 0) { return workerNodeKey - } else if (workerRunTime < minRunTime) { - minRunTime = workerRunTime + } else if (workerTime < minTime) { + minTime = workerTime leastBusyWorkerNodeKey = workerNodeKey } }