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.
|
// Slow path - select other backend urls.
|
||||||
n := atomicCounter.Add(1) - 1
|
n := atomicCounter.Add(1) - 1
|
||||||
buMin := bus[n%uint32(len(bus))]
|
|
||||||
for i := uint32(0); i < uint32(len(bus)); i++ {
|
for i := uint32(0); i < uint32(len(bus)); i++ {
|
||||||
idx := (n + i) % uint32(len(bus))
|
idx := (n + i) % uint32(len(bus))
|
||||||
bu := bus[idx]
|
bu := bus[idx]
|
||||||
if bu.isBroken() {
|
if bu.isBroken() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if buMin.isBroken() {
|
|
||||||
// verify that buMin isn't set as broken
|
|
||||||
buMin = bu
|
|
||||||
}
|
|
||||||
if bu.concurrentRequests.Load() == 0 {
|
if bu.concurrentRequests.Load() == 0 {
|
||||||
// Fast path - return the backend with zero concurrently executed requests.
|
// 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.
|
// 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.
|
// Slow path - return the backend with the minimum number of concurrently executed requests.
|
||||||
|
buMin := bus[n%uint32(len(bus))]
|
||||||
minRequests := buMin.concurrentRequests.Load()
|
minRequests := buMin.concurrentRequests.Load()
|
||||||
for _, bu := range bus {
|
for _, bu := range bus {
|
||||||
if bu.isBroken() {
|
if bu.isBroken() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if n := bu.concurrentRequests.Load(); n < minRequests {
|
if n := bu.concurrentRequests.Load(); n < minRequests || buMin.isBroken() {
|
||||||
buMin = bu
|
buMin = bu
|
||||||
minRequests = n
|
minRequests = n
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue