Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add health check jitter #122

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@

// healthCheck - background routine which checks if a backend is up or down.
func (b *Backend) healthCheck(ctxt context.Context) {
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
timer := time.NewTimer(b.healthCheckDuration)
defer timer.Stop()
for {
Expand All @@ -324,7 +325,8 @@
if err != nil {
console.Errorln(err)
}
timer.Reset(b.healthCheckDuration)
// Add random jitter to call
timer.Reset(b.healthCheckDuration + time.Duration(rng.Int63n(int64(b.healthCheckDuration))))
}
}
}
Expand Down Expand Up @@ -578,7 +580,7 @@
}
switch globalHostBalance {
case "least":
min := int64(math.MaxInt64)

Check failure on line 583 in main.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and ubuntu-latest

redefines-builtin-id: redefinition of the built-in function min (revive)
earliest := int64(math.MaxInt64)
idx := 0
// Shuffle before picking the least connection to ensure all nodes
Expand All @@ -589,7 +591,7 @@
for i, backend := range backends {
currentCalls := backend.Stats.CurrentCalls.Load()
if currentCalls < min {
min = currentCalls

Check failure on line 594 in main.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and ubuntu-latest

redefines-builtin-id: redefinition of the built-in function min (revive)
lastFinished := backend.Stats.LastFinished.Load()
if lastFinished < earliest {
earliest = lastFinished
Expand Down
Loading