Skip to content

Commit

Permalink
Limit events to 100,000 of each type.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vmarmol committed May 1, 2015
1 parent 734df4d commit 1c25746
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions events/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1c25746

Please sign in to comment.