Fix stats collector spinning CPU if no stats are collected
| ... | ... |
@@ -91,6 +91,10 @@ func (s *Collector) Run() {
|
| 91 | 91 |
var pairs []publishersPair |
| 92 | 92 |
|
| 93 | 93 |
for {
|
| 94 |
+ // Put sleep at the start so that it will always be hit, |
|
| 95 |
+ // preventing a tight loop if no stats are collected. |
|
| 96 |
+ time.Sleep(s.interval) |
|
| 97 |
+ |
|
| 94 | 98 |
// it does not make sense in the first iteration, |
| 95 | 99 |
// but saves allocations in further iterations |
| 96 | 100 |
pairs = pairs[:0] |
| ... | ... |
@@ -141,8 +145,6 @@ func (s *Collector) Run() {
|
| 141 | 141 |
logrus.Errorf("collecting stats for %s: %v", pair.container.ID, err)
|
| 142 | 142 |
} |
| 143 | 143 |
} |
| 144 |
- |
|
| 145 |
- time.Sleep(s.interval) |
|
| 146 | 144 |
} |
| 147 | 145 |
} |
| 148 | 146 |
|