X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Ffair-share-worker-choice-strategy.ts;h=fc4bd1fd4de4f281c8dbae20fcf3014ca0a5565f;hb=9fe8fd698590c2494dc6793cfd8c08026fe88a31;hp=f678f83b9719f93c3c3defd2013dec42fea31a8d;hpb=3c93feb918b47943d801029fad82a61469e40127;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 f678f83b..fc4bd1fd 100644 --- a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts @@ -69,9 +69,24 @@ export class FairShareWorkerChoiceStrategy< } /** @inheritDoc */ - public choose (): number { + public choose (): number | undefined { + this.nextWorkerNodeKey = this.fairShareNextWorkerNodeKey() + return this.nextWorkerNodeKey + } + + /** @inheritDoc */ + public remove (workerNodeKey: number): boolean { + this.workersVirtualTaskEndTimestamp.splice(workerNodeKey, 1) + return true + } + + private fairShareNextWorkerNodeKey (): number | undefined { let minWorkerVirtualTaskEndTimestamp = Infinity + let chosenWorkerNodeKey: number | undefined for (const [workerNodeKey] of this.pool.workerNodes.entries()) { + if (!this.isWorkerNodeEligible(workerNodeKey)) { + continue + } if (this.workersVirtualTaskEndTimestamp[workerNodeKey] == null) { this.computeWorkerVirtualTaskEndTimestamp(workerNodeKey) } @@ -79,16 +94,10 @@ export class FairShareWorkerChoiceStrategy< this.workersVirtualTaskEndTimestamp[workerNodeKey] if (workerVirtualTaskEndTimestamp < minWorkerVirtualTaskEndTimestamp) { minWorkerVirtualTaskEndTimestamp = workerVirtualTaskEndTimestamp - this.nextWorkerNodeId = workerNodeKey + chosenWorkerNodeKey = workerNodeKey } } - return this.nextWorkerNodeId - } - - /** @inheritDoc */ - public remove (workerNodeKey: number): boolean { - this.workersVirtualTaskEndTimestamp.splice(workerNodeKey, 1) - return true + return chosenWorkerNodeKey } /**