Fix TM2 poll to randomize start, poll precisely. Fixes Trafic Monitor 2.0 polling to sleep a random time between 0 and the poll interval. This prevents polling all caches at once every tick.
Fixes to poll precisely on the interval, by recreating the ticker. The Go `Ticker` attempts to 'smooth' polls, increasing or decreasing poll times to compensate for slow poll processing. This fixes it to poll at precisely the given interval. Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/80a417b4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/80a417b4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/80a417b4 Branch: refs/heads/master Commit: 80a417b4ba09f0bf963e00cfb4bc15fa32aedc88 Parents: 10129f3 Author: Robert Butts <robert.o.bu...@gmail.com> Authored: Tue Nov 1 16:28:19 2016 -0600 Committer: Dave Neuman <neu...@apache.org> Committed: Mon Nov 7 12:29:08 2016 -0700 ---------------------------------------------------------------------- traffic_monitor/experimental/common/poller/poller.go | 4 ++++ 1 file changed, 4 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/80a417b4/traffic_monitor/experimental/common/poller/poller.go ---------------------------------------------------------------------- diff --git a/traffic_monitor/experimental/common/poller/poller.go b/traffic_monitor/experimental/common/poller/poller.go index a78d767..4609f7a 100644 --- a/traffic_monitor/experimental/common/poller/poller.go +++ b/traffic_monitor/experimental/common/poller/poller.go @@ -2,6 +2,7 @@ package poller import ( "io/ioutil" + "math/rand" "net/http" "os" "sync/atomic" @@ -235,11 +236,14 @@ func (p FilePoller) Poll() { // TODO iterationCount and/or p.TickChan? func pollHttp(interval time.Duration, id string, url string, fetcher fetcher.Fetcher, die <-chan struct{}) { + pollSpread := time.Duration(rand.Float64()*float64(interval/time.Nanosecond)) * time.Nanosecond + time.Sleep(pollSpread) tick := time.NewTicker(interval) lastTime := time.Now() for { select { case now := <-tick.C: + tick = time.NewTicker(interval) // recreate timer, to avoid Go's "smoothing" nonsense realInterval := now.Sub(lastTime) if realInterval > interval+(time.Millisecond*100) { instr.TimerFail.Inc()