@ThreadSafe public class TimeWindowCounter extends Object implements Counter
Counter which keeps track of the increments only over a particular
TimeWindow
, expiring old increments after the window has elapsed. For
example, a period of Uses the resolution of the supplied TimeWindow to group
events together for efficiency. For example, when supplied with a TimeWindow
with a period of 60 seconds and a resolution of 5 seconds, 12 'buckets' will
be created to keep count of events. This means that as each bucket is
overwritten after 60 seconds, the total count may be understated by as much
as (5/60) ≅ 8%. This, however, means that the memory footprint is
approximately that of just the 12 counters, rather than having to track the
time of each individual event.
Currently uses very coarse-grained locking (each get()
or
inc(long)
takes and holds a shared lock for the duration); this may
prove too contentious and require change later.
NULL_COUNTER
Constructor and Description |
---|
TimeWindowCounter(TimeWindow window) |
public TimeWindowCounter(TimeWindow window)
Copyright © 2009–2019 Performance Co-Pilot. All rights reserved.