Skip to content

Commit

Permalink
Merge pull request #2402 from tedyu/period-adjuster
Browse files Browse the repository at this point in the history
Adjust period after each fh.update() call
  • Loading branch information
dashpole authored Feb 28, 2020
2 parents 788b6d4 + 78af2b0 commit ad437f2
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions container/common/fsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,30 @@ func (fh *realFsHandler) update() error {
}

func (fh *realFsHandler) trackUsage() {
fh.update()
longOp := time.Second
for {
start := time.Now()
if err := fh.update(); err != nil {
klog.Errorf("failed to collect filesystem stats - %v", err)
fh.period = fh.period * 2
if fh.period > maxBackoffFactor*fh.minPeriod {
fh.period = maxBackoffFactor * fh.minPeriod
}
} else {
fh.period = fh.minPeriod
}
duration := time.Since(start)
if duration > longOp {
// adapt longOp time so that message doesn't continue to print
// if the long duration is persistent either because of slow
// disk or lots of containers.
longOp = longOp + time.Second
klog.V(2).Infof("fs: disk usage and inodes count on following dirs took %v: %v; will not log again for this container unless duration exceeds %v", duration, []string{fh.rootfs, fh.extraDir}, longOp)
}
select {
case <-fh.stopChan:
return
case <-time.After(fh.period):
start := time.Now()
if err := fh.update(); err != nil {
klog.Errorf("failed to collect filesystem stats - %v", err)
fh.period = fh.period * 2
if fh.period > maxBackoffFactor*fh.minPeriod {
fh.period = maxBackoffFactor * fh.minPeriod
}
} else {
fh.period = fh.minPeriod
}
duration := time.Since(start)
if duration > longOp {
// adapt longOp time so that message doesn't continue to print
// if the long duration is persistent either because of slow
// disk or lots of containers.
longOp = longOp + time.Second
klog.V(2).Infof("fs: disk usage and inodes count on following dirs took %v: %v; will not log again for this container unless duration exceeds %v", duration, []string{fh.rootfs, fh.extraDir}, longOp)
}
}
}
}
Expand Down

0 comments on commit ad437f2

Please sign in to comment.