repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #879 from poolifier/dependabot/npm_and_yarn/examples/typescript...
[poolifier.git]
/
src
/
pools
/
selection-strategies
/
interleaved-weighted-round-robin-worker-choice-strategy.ts
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 cdbfbee5bb0b73e6436f5aad3d94b45e764d3713..4b59a55461e7e92596c5ead2f7fdaca6eabf9d71 100644
(file)
--- 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
@@
-4,7
+4,6
@@
import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
- StrategyPolicy,
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
@@
-22,12
+21,6
@@
export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
- /** @inheritDoc */
- public readonly strategyPolicy: StrategyPolicy = {
- dynamicWorkerUsage: false,
- dynamicWorkerReady: true
- }
-
/**
* Round id.
* This is used to determine the current round weight.
/**
* Round id.
* This is used to determine the current round weight.
@@
-67,15
+60,17
@@
export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
/** @inheritDoc */
public choose (): number | undefined {
/** @inheritDoc */
public choose (): number | undefined {
- let roundId: number
| undefine
d
+ let roundId: number
= this.roundI
d
let workerNodeId: number | undefined
for (
let roundIndex = this.roundId;
roundIndex < this.roundWeights.length;
roundIndex++
) {
let workerNodeId: number | undefined
for (
let roundIndex = this.roundId;
roundIndex < this.roundWeights.length;
roundIndex++
) {
+ roundId = roundIndex
for (
for (
- let workerNodeKey = this.nextWorkerNodeKey ?? 0;
+ let workerNodeKey =
+ this.nextWorkerNodeKey ?? this.previousWorkerNodeKey;
workerNodeKey < this.pool.workerNodes.length;
workerNodeKey++
) {
workerNodeKey < this.pool.workerNodes.length;
workerNodeKey++
) {
@@
-85,13
+80,16
@@
export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
this.isWorkerNodeEligible(workerNodeKey) &&
workerWeight >= this.roundWeights[roundIndex]
) {
this.isWorkerNodeEligible(workerNodeKey) &&
workerWeight >= this.roundWeights[roundIndex]
) {
- roundId = roundIndex
workerNodeId = workerNodeKey
break
}
}
}
workerNodeId = workerNodeKey
break
}
}
}
- this.roundId = roundId as number
+ this.roundId = roundId
+ if (workerNodeId == null) {
+ this.previousWorkerNodeKey =
+ this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
+ }
this.nextWorkerNodeKey = workerNodeId
const chosenWorkerNodeKey = this.nextWorkerNodeKey
if (this.nextWorkerNodeKey === this.pool.workerNodes.length - 1) {
this.nextWorkerNodeKey = workerNodeId
const chosenWorkerNodeKey = this.nextWorkerNodeKey
if (this.nextWorkerNodeKey === this.pool.workerNodes.length - 1) {
@@
-99,7
+97,8
@@
export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
this.roundId =
this.roundId === this.roundWeights.length - 1 ? 0 : this.roundId + 1
} else {
this.roundId =
this.roundId === this.roundWeights.length - 1 ? 0 : this.roundId + 1
} else {
- this.nextWorkerNodeKey = (this.nextWorkerNodeKey ?? 0) + 1
+ this.nextWorkerNodeKey =
+ (this.nextWorkerNodeKey ?? this.previousWorkerNodeKey) + 1
}
return chosenWorkerNodeKey
}
}
return chosenWorkerNodeKey
}