Skip to content

Commit

Permalink
randomly start the probe
Browse files Browse the repository at this point in the history
  • Loading branch information
haoel committed Jul 2, 2022
1 parent e6a7914 commit abc93fd
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/easeprobe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package main

import (
"math/rand"
"sync"
"time"

Expand Down Expand Up @@ -60,6 +61,13 @@ func runProbers(probers []probe.Prober, wg *sync.WaitGroup, done chan bool) {
wg.Add(1)
defer wg.Done()

// Sleep a round time to avoid all probers start at the same time.
s := rand.NewSource(time.Now().UnixNano())
r := rand.New(s)
t := time.Duration(r.Int63n(int64(global.DefaultProbeInterval)))
log.Debugf("[%s / %s] Sleep %v seconds before probe", p.Kind(), p.Name(), t.Seconds())
time.Sleep(t)

interval := time.NewTimer(p.Interval())
defer interval.Stop()
for {
Expand Down

0 comments on commit abc93fd

Please sign in to comment.