mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmauth: simplify the logic for the fix at a0a154511a
The fix ata0a154511a
looks too complicated and fragile: - It moves buMin initialization to the place, which is far from its usage. - It embeds unclear logic on selecting the proper buMin if it is broken, into unrelated loop. The actual fix must be more clear: $ git diff95acca6b52
-- app/vmauth/ - if n := bu.concurrentRequests.Load(); n < minRequests { + if n := bu.concurrentRequests.Load(); n < minRequests || buMin.isBroken() { This should simplify further maintenance of this code. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/7489 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3061
This commit is contained in:
parent
47b7487b5f
commit
83fc33af89
1 changed files with 2 additions and 6 deletions
|
@ -462,17 +462,12 @@ func getLeastLoadedBackendURL(bus []*backendURL, atomicCounter *atomic.Uint32) *
|
|||
|
||||
// Slow path - select other backend urls.
|
||||
n := atomicCounter.Add(1) - 1
|
||||
buMin := bus[n%uint32(len(bus))]
|
||||
for i := uint32(0); i < uint32(len(bus)); i++ {
|
||||
idx := (n + i) % uint32(len(bus))
|
||||
bu := bus[idx]
|
||||
if bu.isBroken() {
|
||||
continue
|
||||
}
|
||||
if buMin.isBroken() {
|
||||
// verify that buMin isn't set as broken
|
||||
buMin = bu
|
||||
}
|
||||
if bu.concurrentRequests.Load() == 0 {
|
||||
// Fast path - return the backend with zero concurrently executed requests.
|
||||
// Do not use CompareAndSwap() instead of Load(), since it is much slower on systems with many CPU cores.
|
||||
|
@ -482,12 +477,13 @@ func getLeastLoadedBackendURL(bus []*backendURL, atomicCounter *atomic.Uint32) *
|
|||
}
|
||||
|
||||
// Slow path - return the backend with the minimum number of concurrently executed requests.
|
||||
buMin := bus[n%uint32(len(bus))]
|
||||
minRequests := buMin.concurrentRequests.Load()
|
||||
for _, bu := range bus {
|
||||
if bu.isBroken() {
|
||||
continue
|
||||
}
|
||||
if n := bu.concurrentRequests.Load(); n < minRequests {
|
||||
if n := bu.concurrentRequests.Load(); n < minRequests || buMin.isBroken() {
|
||||
buMin = bu
|
||||
minRequests = n
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue