Merge pull request #36609 from thaJeztah/fix-stats-loop

Fix stats collector spinning CPU if no stats are collected
This commit is contained in:
John Howard 2018-03-16 10:35:10 -07:00 committed by GitHub
commit 72ba7f593f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -91,6 +91,10 @@ func (s *Collector) Run() {
var pairs []publishersPair
for {
// Put sleep at the start so that it will always be hit,
// preventing a tight loop if no stats are collected.
time.Sleep(s.interval)
// it does not make sense in the first iteration,
// but saves allocations in further iterations
pairs = pairs[:0]
@ -141,8 +145,6 @@ func (s *Collector) Run() {
logrus.Errorf("collecting stats for %s: %v", pair.container.ID, err)
}
}
time.Sleep(s.interval)
}
}