Class SlidingTimeWindowMovingAverages
- All Implemented Interfaces:
MovingAverages
Meter.
The averages are unweighted, i.e. they include strictly only the events in the
sliding time window, every event having the same weight. Unlike the
the more widely used ExponentialMovingAverages implementation,
with this class the moving average rate drops immediately to zero if the last
marked event is older than the time window.
A Meter with SlidingTimeWindowMovingAverages works similarly to
a Histogram with an SlidingTimeWindowArrayReservoir, but as a Meter
needs to keep track only of the count of events (not the events itself), the memory
overhead is much smaller. SlidingTimeWindowMovingAverages uses buckets with just one
counter to accumulate the number of events (one bucket per seconds, giving 900 buckets
for the 15 minutes time window).
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newSlidingTimeWindowMovingAverages.Creates a newSlidingTimeWindowMovingAverages. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the fifteen-minute moving average ratedoubleReturns the one-minute moving average ratedoubleReturns the five-minute moving average ratelonggetSum()voidTick the internal clock of the MovingAverages implementation if needed (according to the internal ticking interval)voidupdate(long n) Update all three moving averages with n events having occurred since the last update.
-
Constructor Details
-
SlidingTimeWindowMovingAverages
public SlidingTimeWindowMovingAverages()Creates a newSlidingTimeWindowMovingAverages. -
SlidingTimeWindowMovingAverages
Creates a newSlidingTimeWindowMovingAverages.- Parameters:
clock- the clock to use for the meter ticks
-
-
Method Details
-
update
public void update(long n) Description copied from interface:MovingAveragesUpdate all three moving averages with n events having occurred since the last update.- Specified by:
updatein interfaceMovingAverages
-
tickIfNecessary
public void tickIfNecessary()Description copied from interface:MovingAveragesTick the internal clock of the MovingAverages implementation if needed (according to the internal ticking interval)- Specified by:
tickIfNecessaryin interfaceMovingAverages
-
getM15Rate
public double getM15Rate()Description copied from interface:MovingAveragesReturns the fifteen-minute moving average rate- Specified by:
getM15Ratein interfaceMovingAverages- Returns:
- the fifteen-minute moving average rate
-
getM5Rate
public double getM5Rate()Description copied from interface:MovingAveragesReturns the five-minute moving average rate- Specified by:
getM5Ratein interfaceMovingAverages- Returns:
- the five-minute moving average rate
-
getM1Rate
public double getM1Rate()Description copied from interface:MovingAveragesReturns the one-minute moving average rate- Specified by:
getM1Ratein interfaceMovingAverages- Returns:
- the one-minute moving average rate
-
getSum
public long getSum()- Specified by:
getSumin interfaceMovingAverages
-