X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Ffair-share-worker-choice-strategy.ts;h=cfda1b0b92b500c86fa0f61cdb49cb0f90c10370;hb=5623b8d539e054f846e86b1f8b3d2e60be748330;hp=00c56dad8f555f64afc0a4d21a693d6a97b956f5;hpb=9b1068374b1a52479b07e1e22b692289d5579237;p=poolifier.git diff --git a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts index 00c56dad..cfda1b0b 100644 --- a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts @@ -8,6 +8,7 @@ import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' import { type IWorkerChoiceStrategy, Measurements, + type StrategyPolicy, type TaskStatisticsRequirements, type WorkerChoiceStrategyOptions } from './selection-strategies-types' @@ -27,6 +28,12 @@ export class FairShareWorkerChoiceStrategy< > extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { + /** @inheritDoc */ + public readonly strategyPolicy: StrategyPolicy = { + dynamicWorkerUsage: false, + dynamicWorkerReady: true + } + /** @inheritDoc */ public readonly taskStatisticsRequirements: TaskStatisticsRequirements = { runTime: { @@ -69,8 +76,9 @@ export class FairShareWorkerChoiceStrategy< } /** @inheritDoc */ - public choose (): number { - this.fairShareNextWorkerNodeKey() + public choose (): number | undefined { + const chosenWorkerNodeKey = this.fairShareNextWorkerNodeKey() + this.assignChosenWorkerNodeKey(chosenWorkerNodeKey) return this.nextWorkerNodeKey } @@ -80,8 +88,9 @@ export class FairShareWorkerChoiceStrategy< return true } - private fairShareNextWorkerNodeKey (): void { + private fairShareNextWorkerNodeKey (): number | undefined { let minWorkerVirtualTaskEndTimestamp = Infinity + let chosenWorkerNodeKey: number | undefined for (const [workerNodeKey] of this.pool.workerNodes.entries()) { if (this.workersVirtualTaskEndTimestamp[workerNodeKey] == null) { this.computeWorkerVirtualTaskEndTimestamp(workerNodeKey) @@ -89,13 +98,14 @@ export class FairShareWorkerChoiceStrategy< const workerVirtualTaskEndTimestamp = this.workersVirtualTaskEndTimestamp[workerNodeKey] if ( - this.isWorkerNodeReady(workerNodeKey) && + this.isWorkerNodeEligible(workerNodeKey) && workerVirtualTaskEndTimestamp < minWorkerVirtualTaskEndTimestamp ) { minWorkerVirtualTaskEndTimestamp = workerVirtualTaskEndTimestamp - this.nextWorkerNodeKey = workerNodeKey + chosenWorkerNodeKey = workerNodeKey } } + return chosenWorkerNodeKey } /**