X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fleast-elu-worker-choice-strategy.ts;h=5df742a665d5d9b5ed838beb887e426da43ade07;hb=5ea80606520ed06f815f4f7485ec9057ac23b176;hp=6b3d10b37da19b31b04258a3452482d7d0a7b258;hpb=f0bbd436ca3a985f79cf530ba82805d8d617d509;p=poolifier.git 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 6b3d10b3..5df742a6 100644 --- a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-elu-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,14 +23,22 @@ export class LeastEluWorkerChoiceStrategy< extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { /** @inheritDoc */ - public readonly taskStatistics: TaskStatistics = { - runTime: false, - avgRunTime: false, - medRunTime: false, - waitTime: false, - avgWaitTime: false, - medWaitTime: false, - elu: true + public readonly taskStatisticsRequirements: TaskStatisticsRequirements = { + runTime: { + aggregate: false, + average: false, + median: false + }, + waitTime: { + aggregate: false, + average: false, + median: false + }, + elu: { + aggregate: true, + average: false, + median: false + } } /** @inheritDoc */ @@ -39,7 +47,7 @@ export class LeastEluWorkerChoiceStrategy< opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS ) { super(pool, opts) - this.setTaskStatistics(this.opts) + this.setTaskStatisticsRequirements(this.opts) } /** @inheritDoc */ @@ -49,24 +57,24 @@ export class LeastEluWorkerChoiceStrategy< /** @inheritDoc */ public update (): boolean { - return true - } - - /** @inheritDoc */ - public choose (): number { let minWorkerElu = Infinity - let leastEluWorkerNodeKey!: number for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerUsage = workerNode.workerUsage - const workerElu = workerUsage.elu?.utilization ?? 0 + const workerElu = workerUsage.elu?.active.aggregate ?? 0 if (workerElu === 0) { - return workerNodeKey + this.nextWorkerNodeId = workerNodeKey + break } else if (workerElu < minWorkerElu) { minWorkerElu = workerElu - leastEluWorkerNodeKey = workerNodeKey + this.nextWorkerNodeId = workerNodeKey } } - return leastEluWorkerNodeKey + return true + } + + /** @inheritDoc */ + public choose (): number { + return this.nextWorkerNodeId } /** @inheritDoc */