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=936fa0fb8e70b2c297938cc9455444486b6daa3e;hp=bf30a4764d4ffdd5287fcbbad588baddca42b193;hpb=20016c79549983d09d30b70852ec7fae515d4156;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 bf30a476..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,10 @@ export class FairShareWorkerChoiceStrategy< } /** @inheritDoc */ - public choose (): number { - return this.fairShareNextWorkerNodeKey() + public choose (): number | undefined { + const chosenWorkerNodeKey = this.fairShareNextWorkerNodeKey() + this.assignChosenWorkerNodeKey(chosenWorkerNodeKey) + return this.nextWorkerNodeKey } /** @inheritDoc */ @@ -79,8 +88,9 @@ export class FairShareWorkerChoiceStrategy< return true } - private fairShareNextWorkerNodeKey (): number { + 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) @@ -88,14 +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 this.nextWorkerNodeKey + return chosenWorkerNodeKey } /**