Top Description Inners Fields Constructors Methods
org.LatencyUtils

public Class TimeCappedMovingAverageIntervalEstimator

extends MovingAverageIntervalEstimator
Class Inheritance
Imports
java.lang.ref.WeakReference, java.util.concurrent.atomic.AtomicLongArray

A moving average interval estimator with a cap on the time window length that the moving window must completely fit in in order to provide estimated time intervals.

A time capped interval estimator is useful for conservatively estimating time intervals in environments where rates can change dramatically and semi-statically. For example, the rate of market rate updates seen just before market close can be very high, dropping dramatically at market close and staying low thereafter. A non-time-capped moving average estimator will project short estimated time interval long after market close, while a time capped interval estimator will avoid carrying the small time interval beyond the time cap.

TimeCappedMovingAverageIntervalEstimator estimates time intervals by averaging the time interval values recorded in a moving window, but if any of the results in the moving window occur outside of the capped time span requested, only the results that fall within the time cap will be considered.

TimeCappedMovingAverageIntervalEstimator can react to pauses reported by an optional PauseDetector by temporarily expanding the time cap to include each pause length, until such a time that the original time cap no longer overlaps with the pause. It will also subtract the pause length from interval times measured across a detected pause. Providing a pause detector is highly recommended, as without one the time cap can cause over-conservative interval estimation (i.e. estimated interval times that are much higher than needed) in the presence of pauses.

All times and time units are in nanoseconds

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
TimeCappedMovingAverageIntervalEstimator.PauseTracker

PauseTracker is used to feed pause correction histograms whenever a pause is reported:

Field Summary

Modifier and TypeField and Description
private final long
private int
private static final int
private int
private AtomicLongArray
private AtomicLongArray
private final TimeCappedMovingAverageIntervalEstimator.PauseTracker
private long
private volatile long
Inherited from org.LatencyUtils.MovingAverageIntervalEstimator:
countintervalEndTimeswindowLengthwindowMagnitudewindowMask

Constructor Summary

AccessConstructor and Description
public
TimeCappedMovingAverageIntervalEstimator(final int
The requested length of the moving window. May be rounded up to nearest power of 2.
requestedWindowLength
,
final long
The cap on time span length (in nanosecond units) in which all window results must fit in order for average estimate to be provided
timeCap
)

public
TimeCappedMovingAverageIntervalEstimator(final int
The requested length of the moving window. May be rounded up to nearest power of 2.
requestedWindowLength
,
final long
The cap on time span length in which all window results must fit in order for average estimate to be provided
timeCap
,
final PauseDetector
The PauseDetector to use to track pauses
pauseDetector
)

Method Summary

Modifier and TypeMethod and Description
private long
private int
private void
eliminateStalePauses(final long when)

public synchronized long
getEstimatedInterval(final long
the time (preferably now) at which the estimated interval is requested.
when
)

Overrides org.LatencyUtils.MovingAverageIntervalEstimator.getEstimatedInterval.

Provides the estimated interval
public void
recordInterval(long
the end time (in nanoTime units) at which the interval was observed.
when
)

Overrides org.LatencyUtils.MovingAverageIntervalEstimator.recordInterval.

Record an interval
private synchronized void
recordPause(final long pauseLength, final long pauseEndTime)

public void
stop()

Stop the tracking via the pauseDetector, and remove this estimator from the pause detector's listeners.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from org.LatencyUtils.MovingAverageIntervalEstimator:
getCurrentPositionrecordIntervalAndReturnWindowPosition

Field Detail

baseTimeCapback to summary
private final long baseTimeCap
earliestPauseIndexback to summary
private int earliestPauseIndex
maxPausesToTrackback to summary
private static final int maxPausesToTrack
nextPauseRecordingIndexback to summary
private int nextPauseRecordingIndex
pauseLengthsback to summary
private AtomicLongArray pauseLengths
pauseStartTimesback to summary
private AtomicLongArray pauseStartTimes
pauseTrackerback to summary
private final TimeCappedMovingAverageIntervalEstimator.PauseTracker pauseTracker
timeCapback to summary
private long timeCap
timeOfLastEstimatedIntervalback to summary
private volatile long timeOfLastEstimatedInterval

Constructor Detail

TimeCappedMovingAverageIntervalEstimatorback to summary
public TimeCappedMovingAverageIntervalEstimator(final int requestedWindowLength, final long timeCap)
Parameters
requestedWindowLength:int

The requested length of the moving window. May be rounded up to nearest power of 2.

timeCap:long

The cap on time span length (in nanosecond units) in which all window results must fit in order for average estimate to be provided

TimeCappedMovingAverageIntervalEstimatorback to summary
public TimeCappedMovingAverageIntervalEstimator(final int requestedWindowLength, final long timeCap, final PauseDetector pauseDetector)
Parameters
requestedWindowLength:int

The requested length of the moving window. May be rounded up to nearest power of 2.

timeCap:long

The cap on time span length in which all window results must fit in order for average estimate to be provided

pauseDetector:PauseDetector

The PauseDetector to use to track pauses

Method Detail

determineEarliestQualifyingTimeInWindowback to summary
private long determineEarliestQualifyingTimeInWindow(final long when)
determineNumberOfWindowPositionsOutsideOfTimeCapback to summary
private int determineNumberOfWindowPositionsOutsideOfTimeCap(long when)
eliminateStalePausesback to summary
private void eliminateStalePauses(final long when)
getEstimatedIntervalback to summary
public synchronized long getEstimatedInterval(final long when)

Overrides org.LatencyUtils.MovingAverageIntervalEstimator.getEstimatedInterval.

Doc from org.LatencyUtils.IntervalEstimator.getEstimatedInterval.

Provides the estimated interval

Parameters
when:long

the time (preferably now) at which the estimated interval is requested.

Returns:long

estimated interval

Annotations
@Override
recordIntervalback to summary
public void recordInterval(long when)

Overrides org.LatencyUtils.MovingAverageIntervalEstimator.recordInterval.

Doc from org.LatencyUtils.IntervalEstimator.recordInterval.

Record an interval

Parameters
when:long

the end time (in nanoTime units) at which the interval was observed.

Annotations
@Override
recordPauseback to summary
private synchronized void recordPause(final long pauseLength, final long pauseEndTime)
stopback to summary
public void stop()

Stop the tracking via the pauseDetector, and remove this estimator from the pause detector's listeners.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.LatencyUtils back to summary

private Class TimeCappedMovingAverageIntervalEstimator.PauseTracker

extends WeakReference<TimeCappedMovingAverageIntervalEstimator>
implements PauseDetectorListener
Class Inheritance
All Implemented Interfaces
org.LatencyUtils.PauseDetectorListener

PauseTracker is used to feed pause correction histograms whenever a pause is reported:

Field Summary

Modifier and TypeField and Description
pack-priv final PauseDetector

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
handlePauseEvent(final long
Length of reported pause (in nanoseconds)
pauseLength
,
final long
Time sampled at end of reported pause (in nanoTime units).
pauseEndTime
)

Implements org.LatencyUtils.PauseDetectorListener.handlePauseEvent.

handle a pause event notification.
public void
stop()

Field Detail

pauseDetectorback to summary
pack-priv final PauseDetector pauseDetector

Constructor Detail

PauseTrackerback to summary
pack-priv PauseTracker(final PauseDetector pauseDetector, final TimeCappedMovingAverageIntervalEstimator estimator)

Method Detail

handlePauseEventback to summary
public void handlePauseEvent(final long pauseLength, final long pauseEndTime)

Implements org.LatencyUtils.PauseDetectorListener.handlePauseEvent.

Doc from org.LatencyUtils.PauseDetectorListener.handlePauseEvent.

handle a pause event notification.

Parameters
pauseLength:long

Length of reported pause (in nanoseconds)

pauseEndTime:long

Time sampled at end of reported pause (in nanoTime units).

stopback to summary
public void stop()