From 33216870d8f7bc079de0ea4870d9e1b2dd2a2b28 Mon Sep 17 00:00:00 2001 From: "Tim St. Clair" Date: Thu, 3 Dec 2015 18:39:11 -0800 Subject: [PATCH] Fix usage of housekeeping_interval flag Defer calculation of `loadDecay`. Flags must be parsed before they can be read, and therefore cannot be reliably be read at package init time. --- manager/container.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/manager/container.go b/manager/container.go index 6f530da13d..e662373073 100644 --- a/manager/container.go +++ b/manager/container.go @@ -44,9 +44,6 @@ var HousekeepingInterval = flag.Duration("housekeeping_interval", 1*time.Second, var cgroupPathRegExp = regexp.MustCompile(".*devices.*:(.*?)[,;$].*") -// Decay value used for load average smoothing. Interval length of 10 seconds is used. -var loadDecay = math.Exp(float64(-1 * (*HousekeepingInterval).Seconds() / 10)) - type containerInfo struct { info.ContainerReference Subcontainers []info.ContainerReference @@ -67,6 +64,9 @@ type containerData struct { lastUpdatedTime time.Time lastErrorTime time.Time + // Decay value used for load average smoothing. Interval length of 10 seconds is used. + loadDecay float64 + // Whether to log the usage of this container when it is updated. logUsage bool @@ -316,6 +316,8 @@ func newContainerData(containerName string, memoryCache *memory.InMemoryCache, h } cont.info.ContainerReference = ref + cont.loadDecay = math.Exp(float64(-cont.housekeepingInterval.Seconds() / 10)) + err = cont.updateSpec() if err != nil { return nil, err @@ -460,7 +462,7 @@ func (c *containerData) updateLoad(newLoad uint64) { if c.loadAvg < 0 { c.loadAvg = float64(newLoad) // initialize to the first seen sample for faster stabilization. } else { - c.loadAvg = c.loadAvg*loadDecay + float64(newLoad)*(1.0-loadDecay) + c.loadAvg = c.loadAvg*c.loadDecay + float64(newLoad)*(1.0-c.loadDecay) } }