Add jitter to housekeeping interval
This commit is contained in:
parent
b0a5bfaf8c
commit
3256647668
@ -19,6 +19,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"math/rand"
|
||||
"os/exec"
|
||||
"path"
|
||||
"regexp"
|
||||
@ -78,6 +79,17 @@ type containerData struct {
|
||||
collectorManager collector.CollectorManager
|
||||
}
|
||||
|
||||
// jitter returns a time.Duration between duration and duration + maxFactor * duration,
|
||||
// to allow clients to avoid converging on periodic behavior. If maxFactor is 0.0, a
|
||||
// suggested default value will be chosen.
|
||||
func jitter(duration time.Duration, maxFactor float64) time.Duration {
|
||||
if maxFactor <= 0.0 {
|
||||
maxFactor = 1.0
|
||||
}
|
||||
wait := duration + time.Duration(rand.Float64()*maxFactor*float64(duration))
|
||||
return wait
|
||||
}
|
||||
|
||||
func (c *containerData) Start() error {
|
||||
go c.housekeeping()
|
||||
return nil
|
||||
@ -356,7 +368,7 @@ func (self *containerData) nextHousekeeping(lastHousekeeping time.Time) time.Tim
|
||||
}
|
||||
}
|
||||
|
||||
return lastHousekeeping.Add(self.housekeepingInterval)
|
||||
return lastHousekeeping.Add(jitter(self.housekeepingInterval, 1.0))
|
||||
}
|
||||
|
||||
// TODO(vmarmol): Implement stats collecting as a custom collector.
|
||||
|
Loading…
Reference in New Issue
Block a user