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=36d1cd4c407c89de4231911bd22cb57b23350781;hpb=8990357d855c45cd0063f24092bb58b4163ddb0a;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 36d1cd4c..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) @@ -92,10 +102,10 @@ export class FairShareWorkerChoiceStrategy< workerVirtualTaskEndTimestamp < minWorkerVirtualTaskEndTimestamp ) { minWorkerVirtualTaskEndTimestamp = workerVirtualTaskEndTimestamp - this.nextWorkerNodeKey = workerNodeKey + chosenWorkerNodeKey = workerNodeKey } } - return this.nextWorkerNodeKey + return chosenWorkerNodeKey } /**