X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Finterleaved-weighted-round-robin-worker-choice-strategy.ts;h=26f9d909eed84f448e0244042d23dc289a26b96a;hb=43b84974f72aecd75b4b592e0009359bd5baf228;hp=40522c72741e67fd6303874f80467e14748d718f;hpb=e102732c0e3966b81834b2c0bdd087eb051162ad;p=poolifier.git diff --git a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts index 40522c72..26f9d909 100644 --- a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts @@ -54,7 +54,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< /** @inheritDoc */ public reset (): boolean { - this.nextWorkerNodeId = 0 + this.nextWorkerNodeKey = 0 this.roundId = 0 return true } @@ -74,13 +74,16 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< roundIndex++ ) { for ( - let workerNodeKey = this.nextWorkerNodeId; + let workerNodeKey = this.nextWorkerNodeKey; workerNodeKey < this.pool.workerNodes.length; workerNodeKey++ ) { const workerWeight = this.opts.weights?.[workerNodeKey] ?? this.defaultWorkerWeight - if (workerWeight >= this.roundWeights[roundIndex]) { + if ( + this.isWorkerNodeReady(workerNodeKey) && + workerWeight >= this.roundWeights[roundIndex] + ) { roundId = roundIndex workerNodeId = workerNodeKey break @@ -88,25 +91,25 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< } } this.roundId = roundId ?? 0 - this.nextWorkerNodeId = workerNodeId ?? 0 - const chosenWorkerNodeKey = this.nextWorkerNodeId - if (this.nextWorkerNodeId === this.pool.workerNodes.length - 1) { - this.nextWorkerNodeId = 0 + this.nextWorkerNodeKey = workerNodeId ?? 0 + const chosenWorkerNodeKey = this.nextWorkerNodeKey + if (this.nextWorkerNodeKey === this.pool.workerNodes.length - 1) { + this.nextWorkerNodeKey = 0 this.roundId = this.roundId === this.roundWeights.length - 1 ? 0 : this.roundId + 1 } else { - this.nextWorkerNodeId = this.nextWorkerNodeId + 1 + this.nextWorkerNodeKey = this.nextWorkerNodeKey + 1 } return chosenWorkerNodeKey } /** @inheritDoc */ public remove (workerNodeKey: number): boolean { - if (this.nextWorkerNodeId === workerNodeKey) { + if (this.nextWorkerNodeKey === workerNodeKey) { if (this.pool.workerNodes.length === 0) { - this.nextWorkerNodeId = 0 - } else if (this.nextWorkerNodeId > this.pool.workerNodes.length - 1) { - this.nextWorkerNodeId = this.pool.workerNodes.length - 1 + this.nextWorkerNodeKey = 0 + } else if (this.nextWorkerNodeKey > this.pool.workerNodes.length - 1) { + this.nextWorkerNodeKey = this.pool.workerNodes.length - 1 this.roundId = this.roundId === this.roundWeights.length - 1 ? 0 : this.roundId + 1 }