Limit events to 100,000 of each type.

This gives us a bit over one event per second for one day. Assuming 250
bytes per event, the max memory usage is ~24MiB per event type.
This commit is contained in:
Victor Marmol 2015-05-01 00:00:46 -07:00
parent 734df4d18c
commit 1c25746cf0
2 changed files with 12 additions and 8 deletions

View File

@ -100,8 +100,10 @@ type events struct {
watcherLock sync.RWMutex
// last allocated watch id.
lastId int
// Max duration for which to keep events.
// Max duration for which to keep events (per event type).
maxAge time.Duration
// Max number of events to keep (per event type).
maxNumEvents int
}
// initialized by a call to WatchEvents(), a watch struct will then be added
@ -128,12 +130,14 @@ func NewEventChannel(watchId int) *EventChannel {
}
// returns a pointer to an initialized Events object.
// eventMaxAge is the max duration for which to keep events.
func NewEventManager(eventMaxAge time.Duration) *events {
// eventMaxAge is the max duration for which to keep events per type.
// maxNumEvents is the max number of events to keep per type (-1 for no limit).
func NewEventManager(eventMaxAge time.Duration, maxNumEvents int) *events {
return &events{
eventStore: make(map[info.EventType]*utils.TimedStore, 0),
watchers: make(map[int]*watch),
maxAge: eventMaxAge,
eventStore: make(map[info.EventType]*utils.TimedStore, 0),
watchers: make(map[int]*watch),
maxAge: eventMaxAge,
maxNumEvents: maxNumEvents,
}
}
@ -262,7 +266,7 @@ func (self *events) updateEventStore(e *info.Event) {
self.eventsLock.Lock()
defer self.eventsLock.Unlock()
if _, ok := self.eventStore[e.EventType]; !ok {
self.eventStore[e.EventType] = utils.NewTimedStore(self.maxAge, -1)
self.eventStore[e.EventType] = utils.NewTimedStore(self.maxAge, self.maxNumEvents)
}
self.eventStore[e.EventType].Add(e.Timestamp, e)
}

View File

@ -137,7 +137,7 @@ func New(memoryStorage *memory.InMemoryStorage, sysfs sysfs.SysFs) (Manager, err
glog.Infof("Version: %+v", newManager.versionInfo)
// TODO(vmarmol): Make configurable.
newManager.eventHandler = events.NewEventManager(24 * time.Hour)
newManager.eventHandler = events.NewEventManager(24*time.Hour, 100000)
// Register Docker container factory.
err = docker.Register(newManager, fsInfo)