Skip to content

Commit

Permalink
Adjust period after each fh.update() call
Browse files Browse the repository at this point in the history
Signed-off-by: Ted Yu <[email protected]>
  • Loading branch information
tedyu committed Feb 28, 2020
1 parent 9268b49 commit 78af2b0
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 78af2b0

Please sign in to comment.