X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fweighted-round-robin-worker-choice-strategy.ts;h=f4bac5d76c4e3b669bb5720b99c03b07eabc577d;hb=aec509b85e7d73e9883c8885e27fc4e34fdaef1e;hp=1bdc02fb189fcf5f21676af2593f2c24854c99dd;hpb=f06e48d8e14dcfe3277bd16b1bd2463136af13e6;p=poolifier.git diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index 1bdc02fb..f4bac5d7 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -1,11 +1,12 @@ import { cpus } from 'node:os' -import type { IPoolInternal } from '../pool-internal' import type { IWorker } from '../worker' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' import type { IWorkerChoiceStrategy, - RequiredStatistics + RequiredStatistics, + WorkerChoiceStrategyOptions } from './selection-strategies-types' +import type { IPool } from '../pool' /** * Virtual task runtime. @@ -57,9 +58,13 @@ export class WeightedRoundRobinWorkerChoiceStrategy< * Constructs a worker choice strategy that selects with a weighted round robin scheduling algorithm. * * @param pool - The pool instance. + * @param opts - The worker choice strategy options. */ - public constructor (pool: IPoolInternal) { - super(pool) + public constructor ( + pool: IPool, + opts?: WorkerChoiceStrategyOptions + ) { + super(pool, opts) this.defaultWorkerWeight = this.computeWorkerWeight() this.initWorkersTaskRunTime() } @@ -146,7 +151,9 @@ export class WeightedRoundRobinWorkerChoiceStrategy< } private getWorkerVirtualTaskRunTime (workerNodeKey: number): number { - return this.pool.workerNodes[workerNodeKey].tasksUsage.avgRunTime + return this.requiredStatistics.medRunTime + ? this.pool.workerNodes[workerNodeKey].tasksUsage.medRunTime + : this.pool.workerNodes[workerNodeKey].tasksUsage.avgRunTime } private computeWorkerWeight (): number {