Make the duration of housekeeping flag configurable.

This commit is contained in:
Victor Marmol 2014-08-30 19:57:53 -07:00
parent cf725b2173
commit 3d10fc747c
3 changed files with 34 additions and 14 deletions

View File

@ -17,6 +17,7 @@
package manager
import (
"flag"
"fmt"
"sync"
"time"
@ -27,8 +28,8 @@ import (
"github.com/google/cadvisor/storage"
)
// Housekeeping duration
const HousekeepingTick = 1 * time.Second
// Housekeeping interval.
var HousekeepingInterval = flag.Duration("housekeeping_interval", 1*time.Second, "Interval between container housekeepings")
// Internal mirror of the external data structure.
type containerStat struct {
@ -107,8 +108,14 @@ func NewContainerData(containerName string, driver storage.StorageDriver) (*cont
}
func (c *containerData) housekeeping() {
// Long housekeeping is either 100ms or half of the housekeeping interval.
longHousekeeping := 100 * time.Millisecond
if *HousekeepingInterval/2 < longHousekeeping {
longHousekeeping = *HousekeepingInterval / 2
}
// Housekeep every second.
ticker := time.NewTicker(HousekeepingTick)
ticker := time.NewTicker(*HousekeepingInterval)
defer ticker.Stop()
for {
select {
@ -119,10 +126,10 @@ func (c *containerData) housekeeping() {
start := time.Now()
c.housekeepingTick()
// Log if housekeeping took longer than 120ms.
// Log if housekeeping took too long.
duration := time.Since(start)
if duration >= 120*time.Millisecond {
glog.V(2).Infof("Housekeeping(%s) took %s", c.info.Name, duration)
if duration >= longHousekeeping {
glog.V(1).Infof("Housekeeping(%s) took %s", c.info.Name, duration)
}
}
}

View File

@ -15,6 +15,7 @@
package manager
import (
"flag"
"fmt"
"path"
"strings"
@ -27,6 +28,8 @@ import (
"github.com/google/cadvisor/storage"
)
var globalHousekeepingInterval = flag.Duration("global_housekeeping_interval", 1*time.Second, "Interval between global housekeepings")
type Manager interface {
// Start the manager, blocks forever.
Start() error
@ -70,11 +73,13 @@ func New(driver storage.StorageDriver) (Manager, error) {
}
type manager struct {
containers map[string]*containerData
containersLock sync.RWMutex
storageDriver storage.StorageDriver
machineInfo info.MachineInfo
versionInfo info.VersionInfo
containers map[string]*containerData
containersLock sync.RWMutex
storageDriver storage.StorageDriver
machineInfo info.MachineInfo
versionInfo info.VersionInfo
globalHousekeepingInterval time.Duration
containerHousekeepingInterval time.Duration
}
// Start the container manager.
@ -91,8 +96,15 @@ func (m *manager) Start() error {
}
glog.Infof("Recovery completed")
// Long housekeeping is either 100ms or half of the housekeeping interval.
longHousekeeping := 100 * time.Millisecond
if *globalHousekeepingInterval/2 < longHousekeeping {
longHousekeeping = *globalHousekeepingInterval / 2
}
// Look for new containers in the main housekeeping thread.
for t := range time.Tick(time.Second) {
ticker := time.Tick(*globalHousekeepingInterval)
for t := range ticker {
start := time.Now()
// Check for new containers.
@ -103,7 +115,7 @@ func (m *manager) Start() error {
// Log if housekeeping took more than 100ms.
duration := time.Since(start)
if duration >= 100*time.Millisecond {
if duration >= longHousekeeping {
glog.V(1).Infof("Global Housekeeping(%d) took %s", t.Unix(), duration)
}
}

View File

@ -42,7 +42,8 @@ const statsRequestedByUI = 60
func NewStorageDriver(driverName string) (storage.StorageDriver, error) {
var storageDriver storage.StorageDriver
var err error
samplesToCache := int(*argDbBufferDuration / manager.HousekeepingTick)
// TODO(vmarmol): We shouldn't need the housekeeping interval here and it shouldn't be public.
samplesToCache := int(*argDbBufferDuration / *manager.HousekeepingInterval)
if samplesToCache < statsRequestedByUI {
// The UI requests the most recent 60 stats by default.
samplesToCache = statsRequestedByUI