Skip to content

Commit

Permalink
Distribute to all nodes if the load is low to medium (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
vadmeste authored Feb 15, 2024
1 parent 4857571 commit a245df1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,14 @@ func (s *site) nextProxy() (*Backend, func()) {
}
switch globalHostBalance {
case "least":
min := int64(math.MaxInt32)
earliest := time.Now().Add(time.Second).UnixNano()
min := int64(math.MaxInt64)
earliest := int64(math.MaxInt64)
idx := 0
// Shuffle before picking the least connection to ensure all nodes
// are involved if the load is low to medium.
rand.Shuffle(len(backends), func(i, j int) {
backends[i], backends[j] = backends[j], backends[i]
})
for i, backend := range backends {
currentCalls := backend.Stats.CurrentCalls.Load()
if currentCalls < min {
Expand Down

0 comments on commit a245df1

Please sign in to comment.