diff --git a/container/docker/fsHandler.go b/container/docker/fsHandler.go index ac18d336..0792ebac 100644 --- a/container/docker/fsHandler.go +++ b/container/docker/fsHandler.go @@ -36,6 +36,7 @@ type realFsHandler struct { usageBytes uint64 baseUsageBytes uint64 period time.Duration + minPeriod time.Duration rootfs string extraDir string fsInfo fs.FsInfo @@ -44,8 +45,9 @@ type realFsHandler struct { } const ( - longDu = time.Second - duTimeout = time.Minute + longDu = time.Second + duTimeout = time.Minute + maxDuBackoffFactor = 20 ) var _ fsHandler = &realFsHandler{} @@ -56,6 +58,7 @@ func newFsHandler(period time.Duration, rootfs, extraDir string, fsInfo fs.FsInf usageBytes: 0, baseUsageBytes: 0, period: period, + minPeriod: period, rootfs: rootfs, extraDir: extraDir, fsInfo: fsInfo, @@ -63,10 +66,6 @@ func newFsHandler(period time.Duration, rootfs, extraDir string, fsInfo fs.FsInf } } -func (fh *realFsHandler) needsUpdate() bool { - return time.Now().After(fh.lastUpdate.Add(fh.period)) -} - func (fh *realFsHandler) update() error { // TODO(vishh): Add support for external mounts. baseUsage, err := fh.fsInfo.GetDirUsage(fh.rootfs, duTimeout) @@ -97,6 +96,12 @@ func (fh *realFsHandler) trackUsage() { start := time.Now() if err := fh.update(); err != nil { glog.Errorf("failed to collect filesystem stats - %v", err) + fh.period = fh.period * 2 + if fh.period > maxDuBackoffFactor*fh.minPeriod { + fh.period = maxDuBackoffFactor * fh.minPeriod + } + } else { + fh.period = fh.minPeriod } duration := time.Since(start) if duration > longDu {