Skip to content

Commit

Permalink
Added fadein for powerOfRandomNChoices as well
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Zavodskikh <[email protected]>
  • Loading branch information
Roman Zavodskikh committed Aug 16, 2023
1 parent 015b62f commit 8d8ad81
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions loadbalancer/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,16 @@ func newPowerOfRandomNChoices([]string) routing.LBAlgorithm {

// Apply implements routing.LBAlgorithm with power of random N choices algorithm.
func (p *powerOfRandomNChoices) Apply(ctx *routing.LBContext) routing.LBEndpoint {
ne := len(ctx.Route.LBEndpoints)
endpoints := ctx.Route.GetHealthyEndpoints()
ne := len(endpoints)

p.mx.Lock()
defer p.mx.Unlock()

best := ctx.Route.LBEndpoints[p.rnd.Intn(ne)]
best := endpoints[p.rnd.Intn(ne)]

for i := 1; i < p.numberOfChoices; i++ {
ce := ctx.Route.LBEndpoints[p.rnd.Intn(ne)]
ce := endpoints[p.rnd.Intn(ne)]

if p.getScore(ce) > p.getScore(best) {
best = ce
Expand Down

0 comments on commit 8d8ad81

Please sign in to comment.