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

Enhancement: Equally distributing start the probers. #157

Merged
merged 3 commits into from
Jul 3, 2022
Merged
Changes from all commits
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
15 changes: 13 additions & 2 deletions cmd/easeprobe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,20 @@ func configProbers(probers []probe.Prober) []probe.Prober {
}

func runProbers(probers []probe.Prober, wg *sync.WaitGroup, done chan bool) {
probeFn := func(p probe.Prober) {
// we need to run all probers in equally distributed time, not at the same time.
timeGap := global.DefaultProbeInterval / time.Duration(len(probers))
log.Debugf("Start Time Gap: %v = %v / %d", timeGap, global.DefaultProbeInterval, len(probers))

probeFn := func(p probe.Prober, index int) {
wg.Add(1)
defer wg.Done()

// Sleep a round time to avoid all probers start at the same time.
t := time.Duration(index) * timeGap
log.Debugf("[%s / %s] Delay %v = (%d * %v) seconds to start the probe work",
p.Kind(), p.Name(), t, index, timeGap)
time.Sleep(t)

interval := time.NewTimer(p.Interval())
defer interval.Stop()
for {
Expand All @@ -82,12 +92,13 @@ func runProbers(probers []probe.Prober, wg *sync.WaitGroup, done chan bool) {
}
}
}

for i := 0; i < len(probers); i++ {
p := probers[i]
if p.Result().Status == probe.StatusBad {
continue
}
log.Infof("Ready to monitor(%s): %s - %s", p.Kind(), p.Result().Name, p.Result().Endpoint)
go probeFn(p)
go probeFn(p, i)
}
}