mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-11 22:30:47 +01:00
feat(health): add random delay to health monitor to prevent thundering herd problem
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
@@ -141,6 +142,9 @@ func (mon *monitor) Start(parent task.Parent) gperr.Error {
|
||||
failures++
|
||||
}
|
||||
|
||||
// add a random delay between 0 and 10 seconds to avoid thundering herd
|
||||
time.Sleep(time.Duration(rand.Intn(10)) * time.Second)
|
||||
|
||||
ticker := time.NewTicker(mon.config.Interval)
|
||||
defer ticker.Stop()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user