-
Notifications
You must be signed in to change notification settings - Fork 18.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix stats collector spinning CPU if no stats are collected #36609
Conversation
Commit fd0e24b changed the stats collection loop to use a `sleep()` instead of `time.Tick()` in the for-loop. This change caused a regression in situations where no stats are being collected, or an error is hit in the loop (in which case the loop would `continue`, and the `sleep()` is not hit). This patch puts the sleep at the start of the loop to guarantee it's always hit. This will delay the sampling, which is similar to the behavior before fd0e24b. Signed-off-by: Sebastiaan van Stijn <[email protected]>
ping @stevvooe @jhowardmsft PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily horrible, but this delays the initial collection.
What about a goto Sleep
?
@cpuguy83 I'm not a big fan of The loop is started when the daemon starts, so it would be a 1 second delay once, after the daemon starts. Situation before #36519 was applied (using diff --git a/daemon/stats/collector.go b/daemon/stats/collector.go
index 88e20984b..d8045710a 100644
--- a/daemon/stats/collector.go
+++ b/daemon/stats/collector.go
@@ -90,10 +90,12 @@ func (s *Collector) Run() {
// it will grow enough in first iteration
var pairs []publishersPair
- for {
+ logrus.Debugf("starting to collect stats")
+ for range time.Tick(s.interval) {
// 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)
+ //time.Sleep(s.interval)
+ logrus.Debugf("collecting stats")
// it does not make sense in the first iteration,
// but saves allocations in further iterations
Situation in this PR ( diff --git a/daemon/stats/collector.go b/daemon/stats/collector.go
index 88e20984b..7f9735293 100644
--- a/daemon/stats/collector.go
+++ b/daemon/stats/collector.go
@@ -90,10 +90,12 @@ func (s *Collector) Run() {
// it will grow enough in first iteration
var pairs []publishersPair
+ logrus.Debugf("starting to collect stats")
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)
+ logrus.Debugf("collecting stats")
// it does not make sense in the first iteration,
// but saves allocations in further iterations
|
The
|
Codecov Report
@@ Coverage Diff @@
## master #36609 +/- ##
=========================================
Coverage ? 34.69%
=========================================
Files ? 612
Lines ? 45424
Branches ? 0
=========================================
Hits ? 15759
Misses ? 27603
Partials ? 2062 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM since this is happening at daemon start it seems fine.
fixes #36608
Commit fd0e24b (#36519) changed the stats collection loop to use a
sleep()
instead oftime.Tick()
in the for-loop.This change caused a regression in situations where no stats are being collected, or an error is hit in the loop (in which case the loop would
continue
, and thesleep()
is not hit).This patch puts the sleep at the start of the loop to guarantee it's always hit.
This will delay the sampling, which is similar to the behavior before fd0e24b.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)