Skip to content

Commit

Permalink
notice
Browse files Browse the repository at this point in the history
Signed-off-by: dsxing <[email protected]>
  • Loading branch information
dsxing committed Apr 17, 2024
1 parent 54dff2b commit a3b5f5b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cache/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ func (c *InMemoryCache) RemoveContainer(containerName string) error {
return nil
}

func (c *InMemoryCache) GetMaxAge() time.Duration {
return c.maxAge
}

func New(
maxAge time.Duration,
backend []storage.StorageDriver,
Expand Down
20 changes: 19 additions & 1 deletion manager/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ import (

// Housekeeping interval.
var enableLoadReader = flag.Bool("enable_load_reader", false, "Whether to enable cpu load reader")
var HousekeepingInterval = flag.Duration("housekeeping_interval", 1*time.Second, "Interval between container housekeepings")
var HousekeepingInterval = flag.Duration("housekeeping_interval", 1*time.Second, "Interval between container housekeepings."+
" It should be less than 'max_housekeeping_interval',"+
" and it must be less than memory's maxAge('storage_duration'), which is set to 2 minutes by default.")

// TODO: replace regular expressions with something simpler, such as strings.Split().
// cgroup type chosen to fetch the cgroup path of a process.
Expand Down Expand Up @@ -496,6 +498,22 @@ func (cd *containerData) nextHousekeepingInterval() time.Duration {
// Lower interval back to the baseline.
cd.housekeepingInterval = *HousekeepingInterval
}
} else if len(stats) < 2 {
// Lower the interval if less than two stats

// If set housekeepingInterval and maxHousekeepingInterval to large values, both greater than memoryCache.maxAge.
if cd.housekeepingInterval >= cd.memoryCache.GetMaxAge() &&
cd.maxHousekeepingInterval >= cd.memoryCache.GetMaxAge() &&
*HousekeepingInterval >= cd.memoryCache.GetMaxAge() {
const defaultHousekeepingInterval = 10 * time.Second
cd.housekeepingInterval = cd.memoryCache.GetMaxAge() - defaultHousekeepingInterval
} else if cd.housekeepingInterval > cd.maxHousekeepingInterval {
// Due to the lack of enforced validation, incorrect settings may occur.
cd.housekeepingInterval = cd.maxHousekeepingInterval
} else {
// Lower interval back to the baseline.
cd.housekeepingInterval = *HousekeepingInterval
}
}
}

Expand Down

0 comments on commit a3b5f5b

Please sign in to comment.