From 9d508c59503e829351885dc1bc7d5591a76133c6 Mon Sep 17 00:00:00 2001 From: yusing Date: Sun, 28 Sep 2025 02:35:44 +0800 Subject: [PATCH] feat(health): add random delay to health monitor to prevent thundering herd problem --- internal/watcher/health/monitor/monitor.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/watcher/health/monitor/monitor.go b/internal/watcher/health/monitor/monitor.go index 7cbc5e2c..f2570c97 100644 --- a/internal/watcher/health/monitor/monitor.go +++ b/internal/watcher/health/monitor/monitor.go @@ -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()