X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fless-busy-worker-choice-strategy.ts;h=02f51c6b0194dec3a0c21b38beadbad0a6b943ef;hb=0567595a23237d7b0e4bc0ec70c8e313eb71bb10;hp=12e87ff2575649c6c1a9847d8dd24a9ad1e30f9a;hpb=027063571693f211b35c8851566a063201adb9af;p=poolifier.git diff --git a/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts b/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts index 12e87ff2..02f51c6b 100644 --- a/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts @@ -1,8 +1,11 @@ +import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils' +import type { IPool } from '../pool' import type { IWorker } from '../worker' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' import type { IWorkerChoiceStrategy, - RequiredStatistics + RequiredStatistics, + WorkerChoiceStrategyOptions } from './selection-strategies-types' /** @@ -23,7 +26,19 @@ export class LessBusyWorkerChoiceStrategy< public readonly requiredStatistics: RequiredStatistics = { runTime: true, avgRunTime: false, - medRunTime: false + medRunTime: false, + waitTime: false, + avgWaitTime: false, + medWaitTime: false + } + + /** @inheritDoc */ + public constructor ( + pool: IPool, + opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS + ) { + super(pool, opts) + this.setRequiredStatistics(this.opts) } /** @inheritDoc */ @@ -31,28 +46,33 @@ export class LessBusyWorkerChoiceStrategy< return true } + /** @inheritDoc */ + public update (): boolean { + return true + } + /** @inheritDoc */ public choose (): number { - const freeWorkerNodeKey = this.pool.findFreeWorkerNodeKey() + const freeWorkerNodeKey = this.findFreeWorkerNodeKey() if (freeWorkerNodeKey !== -1) { return freeWorkerNodeKey } let minRunTime = Infinity let lessBusyWorkerNodeKey!: number - for (const [index, workerNode] of this.pool.workerNodes.entries()) { + for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerRunTime = workerNode.tasksUsage.runTime if (workerRunTime === 0) { - return index + return workerNodeKey } else if (workerRunTime < minRunTime) { minRunTime = workerRunTime - lessBusyWorkerNodeKey = index + lessBusyWorkerNodeKey = workerNodeKey } } return lessBusyWorkerNodeKey } /** @inheritDoc */ - public remove (workerNodeKey: number): boolean { + public remove (): boolean { return true } }