Skip to content

Commit 1d6e0ec

Browse files
committed
Merge pull request #1002 from timstclair/loaddecay
Fix usage of housekeeping_interval flag
2 parents 3b10b41 + 3321687 commit 1d6e0ec

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

manager/container.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ var HousekeepingInterval = flag.Duration("housekeeping_interval", 1*time.Second,
4545

4646
var cgroupPathRegExp = regexp.MustCompile(`.*devices.*:(.*?)[,;$].*`)
4747

48-
// Decay value used for load average smoothing. Interval length of 10 seconds is used.
49-
var loadDecay = math.Exp(float64(-1 * (*HousekeepingInterval).Seconds() / 10))
50-
5148
type containerInfo struct {
5249
info.ContainerReference
5350
Subcontainers []info.ContainerReference
@@ -68,6 +65,9 @@ type containerData struct {
6865
lastUpdatedTime time.Time
6966
lastErrorTime time.Time
7067

68+
// Decay value used for load average smoothing. Interval length of 10 seconds is used.
69+
loadDecay float64
70+
7171
// Whether to log the usage of this container when it is updated.
7272
logUsage bool
7373

@@ -317,6 +317,8 @@ func newContainerData(containerName string, memoryCache *memory.InMemoryCache, h
317317
}
318318
cont.info.ContainerReference = ref
319319

320+
cont.loadDecay = math.Exp(float64(-cont.housekeepingInterval.Seconds() / 10))
321+
320322
err = cont.updateSpec()
321323
if err != nil {
322324
return nil, err
@@ -464,7 +466,7 @@ func (c *containerData) updateLoad(newLoad uint64) {
464466
if c.loadAvg < 0 {
465467
c.loadAvg = float64(newLoad) // initialize to the first seen sample for faster stabilization.
466468
} else {
467-
c.loadAvg = c.loadAvg*loadDecay + float64(newLoad)*(1.0-loadDecay)
469+
c.loadAvg = c.loadAvg*c.loadDecay + float64(newLoad)*(1.0-c.loadDecay)
468470
}
469471
}
470472

0 commit comments

Comments
 (0)