Top Description Inners Fields Constructors Methods
org.LatencyUtils

public Class LatencyStats

extends Object
Class Inheritance
Imports
org.HdrHistogram.Histogram, .AtomicHistogram, .WriterReaderPhaser, java.lang.ref.WeakReference

LatencyStats objects are used to track and report on the behavior of latencies across measurements. recorded into a a given LatencyStats instance. Latencies are recorded using recordLatency, which provides a thread safe, wait free, and lossless recording method. The accumulated behavior across the recorded latencies in a given LatencyStats instance can be examined in detail using interval and accumulated HdrHistogram histograms (see org.HdrHistogram.Histogram).

LatencyStats instances maintain internal histogram data that track all recoded latencies. Interval histogram data can be sampled with the getIntervalHistogram, getIntervalHistogramInto, or addIntervalHistogramTo calls.

Recorded latencies are auto-corrected for experienced pauses by leveraging pause detectors and moving window average interval estimators, compensating for coordinated omission. While typical histogram use deals with corrected data, LatencyStats instances do keep track of the raw, uncorrected records, which can be accessed via the getLatestUncorrectedIntervalHistogram and getLatestUncorrectedIntervalHistogramInto calls.

LatencyStats objects can be instantiated either directly via the provided constructors, or by using the fluent API builder supported by org.LatencyUtils.LatencyStats.Builder.

Correction Technique

In addition to tracking the raw latency recordings provided via recordLatency, each LatencyStats instance maintains an internal interval estimator that tracks the expected interval between latency recordings. Whenever a stall in measurement is detected by a given pause detector, each LatencyStats instances that uses that pause detector will be notified, and will generate correcting latency entries (that are separately tracked internally). Correcting latency entries are computed to "fill in" detected measurement pauses by projecting the observed recording rate into the pause gap, and creating a linearly diminishing latency measurement for each missed recording interval.

Pause detection and interval estimation are both configurable, and each LatencyStats instance can operate with potentially independent pause detector and interval estimator settings.

A configurable default pause detector is (by default) shared between LatencyStats instances that are not provided with a specific pause detector at instantiation. If the default pause detector is not explicitly set, it will itself default to creating (and starting) a single instance of org.LatencyUtils.SimplePauseDetector, which uses consensus observation of a pause across multiple observing threads as a detection technique.

Custom pause detectors can be provided (by subclassing org.LatencyUtils.PauseDetector). E.g. a pause detector that pauses GC log output rather than directly measuring observations can be constructed. A custom pause detector can be especially useful in situations where a stall in the operation and latency measurement of an application's is known and detectable by the application level, but would not be detectable as a process-wide stall in execution (which org.LatencyUtils.SimplePauseDetector is built to detect).

Interval estimation is done by using a time-capped moving window average estimator, with the expected interval computed to be the average of measurement intervals within the window (with the window being capped by both count and time). See TimeCappedMovingAverageIntervalEstimator for more details. The estimator window length and time cap can both be configured when instantiating a LatencyStats object (defaults are 1024, and 10 seconds).

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
LatencyStats.Builder

A fluent API builder class for creating LatencyStats objects.

private static class
LatencyStats.PauseTracker

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

Field Summary

Modifier and TypeField and Description
private Histogram
private volatile AtomicHistogram
private static LatencyStats.Builder
private static PauseDetector
private final long
private Histogram
private AtomicHistogram
private final IntervalEstimator
private static final TimeServices.ScheduledExecutor
private final long
private final int
private final PauseDetector
private final LatencyStats.PauseTracker
private final WriterReaderPhaser

Constructor Summary

AccessConstructor and Description
public
LatencyStats()

Create a LatencyStats object with default settings.

public
LatencyStats(final long
Lowest trackable latency in latency histograms
lowestTrackableLatency
,
final long
Highest trackable latency in latency histograms
highestTrackableLatency
,
final int
Number of significant [decimal] digits of accuracy in latency histograms
numberOfSignificantValueDigits
,
final int
Length of window in moving window interval estimator
intervalEstimatorWindowLength
,
final long
Time cap (in nanoseconds) of window in moving window interval estimator
intervalEstimatorTimeCap
,
final PauseDetector
The pause detector to use for identifying and correcting for pauses
pauseDetector
)

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addIntervalHistogramTo(Histogram
the histogram into which the interval histogram's data should be added
toHistogram
)

Add the values value counts accumulated since the last interval histogram was taken into toHistogram.

public static PauseDetector

Returns:

the current default pause detector
getDefaultPauseDetector
()

Get the current default pause detector which will be used by newly constructed LatencyStats instances when the constructor is not explicitly provided with one.

public IntervalEstimator

Returns:

the IntervalEstimator used by this LatencyStats object
getIntervalEstimator
()

get the IntervalEstimator used by this LatencyStats object

public synchronized Histogram

Returns:

a copy of the latest interval latency histogram
getIntervalHistogram
()

Get a new interval histogram which will include the value counts accumulated since the last interval histogram was taken.

public synchronized void
getIntervalHistogramInto(Histogram
the histogram into which the interval histogram's data should be copied
targetHistogram
)

Place a copy of the value counts accumulated since the last interval histogram was taken into targetHistogram.

public synchronized Histogram

Returns:

a copy of the latest uncorrected interval latency histogram
getLatestUncorrectedIntervalHistogram
()

Get a copy of the uncorrected latest interval latency histogram.

public synchronized void
getLatestUncorrectedIntervalHistogramInto(Histogram
the histogram into which the interval histogram's data should be copied
targetHistogram
)

Place a copy of the values of the latest uncorrected interval latency histogram.

public PauseDetector

Returns:

the PauseDetector used by this LatencyStats object
getPauseDetector
()

get the PauseDetector used by this LatencyStats object

private synchronized void
recordDetectedPause(long pauseLength, long pauseEndTime)

public void
recordLatency(long
latency value (in nanoseconds) to record
latency
)

Record a latency value in the LatencyStats object

public static void
setDefaultPauseDetector(PauseDetector
the pause detector to use as a default when no explicit pause detector is provided
pauseDetector
)

Set the default pause detector for the LatencyStats class.

public synchronized void
stop()

Stop operation of this LatencyStats object, removing it from the pause detector's notification list

private synchronized void
private void
private void
private void
private synchronized void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activePauseCorrectionsHistogramback to summary
private Histogram activePauseCorrectionsHistogram
activeRecordingHistogramback to summary
private volatile AtomicHistogram activeRecordingHistogram
defaultBuilderback to summary
private static LatencyStats.Builder defaultBuilder
defaultPauseDetectorback to summary
private static PauseDetector defaultPauseDetector
highestTrackableLatencyback to summary
private final long highestTrackableLatency
inactivePauseCorrectionsHistogramback to summary
private Histogram inactivePauseCorrectionsHistogram
inactiveRawDataHistogramback to summary
private AtomicHistogram inactiveRawDataHistogram
intervalEstimatorback to summary
private final IntervalEstimator intervalEstimator
latencyStatsScheduledExecutorback to summary
private static final TimeServices.ScheduledExecutor latencyStatsScheduledExecutor
lowestTrackableLatencyback to summary
private final long lowestTrackableLatency
numberOfSignificantValueDigitsback to summary
private final int numberOfSignificantValueDigits
pauseDetectorback to summary
private final PauseDetector pauseDetector
pauseTrackerback to summary
private final LatencyStats.PauseTracker pauseTracker
recordingPhaserback to summary
private final WriterReaderPhaser recordingPhaser

Constructor Detail

LatencyStatsback to summary
public LatencyStats()

Create a LatencyStats object with default settings.

  • use the default pause detector (supplied separately set using setDefaultPauseDetector, which will itself default to a SimplePauseDetector if not explicitly supplied)
  • use a default histogram update interval (1 sec)
  • use a default histogram range and accuracy (1 usec to 1hr, 2 decimal points of accuracy)
  • and use a default moving window estimator (1024 entry moving window, time capped at 10 seconds)
LatencyStatsback to summary
public LatencyStats(final long lowestTrackableLatency, final long highestTrackableLatency, final int numberOfSignificantValueDigits, final int intervalEstimatorWindowLength, final long intervalEstimatorTimeCap, final PauseDetector pauseDetector)
Parameters
lowestTrackableLatency:long

Lowest trackable latency in latency histograms

highestTrackableLatency:long

Highest trackable latency in latency histograms

numberOfSignificantValueDigits:int

Number of significant [decimal] digits of accuracy in latency histograms

intervalEstimatorWindowLength:int

Length of window in moving window interval estimator

intervalEstimatorTimeCap:long

Time cap (in nanoseconds) of window in moving window interval estimator

pauseDetector:PauseDetector

The pause detector to use for identifying and correcting for pauses

Method Detail

addIntervalHistogramToback to summary
public synchronized void addIntervalHistogramTo(Histogram toHistogram)

Add the values value counts accumulated since the last interval histogram was taken into toHistogram. Calling addIntervalHistogramTo() will reset the interval value counts, and start accumulating value counts for the next interval.

Parameters
toHistogram:Histogram

the histogram into which the interval histogram's data should be added

getDefaultPauseDetectorback to summary
public static PauseDetector getDefaultPauseDetector()

Get the current default pause detector which will be used by newly constructed LatencyStats instances when the constructor is not explicitly provided with one.

Returns:PauseDetector

the current default pause detector

getIntervalEstimatorback to summary
public IntervalEstimator getIntervalEstimator()

get the IntervalEstimator used by this LatencyStats object

Returns:IntervalEstimator

the IntervalEstimator used by this LatencyStats object

getIntervalHistogramback to summary
public synchronized Histogram getIntervalHistogram()

Get a new interval histogram which will include the value counts accumulated since the last interval histogram was taken.

Calling getIntervalHistogram() will reset the interval value counts, and start accumulating value counts for the next interval.

Returns:Histogram

a copy of the latest interval latency histogram

getIntervalHistogramIntoback to summary
public synchronized void getIntervalHistogramInto(Histogram targetHistogram)

Place a copy of the value counts accumulated since the last interval histogram was taken into targetHistogram. Calling getIntervalHistogramInto() will reset the interval value counts, and start accumulating value counts for the next interval.

Parameters
targetHistogram:Histogram

the histogram into which the interval histogram's data should be copied

getLatestUncorrectedIntervalHistogramback to summary
public synchronized Histogram getLatestUncorrectedIntervalHistogram()

Get a copy of the uncorrected latest interval latency histogram. Values will not include corrections for detected pauses. The interval histogram copies will include all values points captured up to the latest call to call to one of getIntervalHistogram, getIntervalHistogramInto, or addIntervalHistogramTo.

Returns:Histogram

a copy of the latest uncorrected interval latency histogram

getLatestUncorrectedIntervalHistogramIntoback to summary
public synchronized void getLatestUncorrectedIntervalHistogramInto(Histogram targetHistogram)

Place a copy of the values of the latest uncorrected interval latency histogram. Values will not include corrections for detected pauses. The interval histogram copies will include all values points captured up to the latest call to call to one of getIntervalHistogram, getIntervalHistogramInto, or addIntervalHistogramTo.

Parameters
targetHistogram:Histogram

the histogram into which the interval histogram's data should be copied

getPauseDetectorback to summary
public PauseDetector getPauseDetector()

get the PauseDetector used by this LatencyStats object

Returns:PauseDetector

the PauseDetector used by this LatencyStats object

recordDetectedPauseback to summary
private synchronized void recordDetectedPause(long pauseLength, long pauseEndTime)
recordLatencyback to summary
public void recordLatency(long latency)

Record a latency value in the LatencyStats object

Parameters
latency:long

latency value (in nanoseconds) to record

setDefaultPauseDetectorback to summary
public static void setDefaultPauseDetector(PauseDetector pauseDetector)

Set the default pause detector for the LatencyStats class. Used by constructors that do not explicitly provide a pause detector.

Parameters
pauseDetector:PauseDetector

the pause detector to use as a default when no explicit pause detector is provided

stopback to summary
public synchronized void stop()

Stop operation of this LatencyStats object, removing it from the pause detector's notification list

swapHistogramsback to summary
private synchronized void swapHistograms()
swapPauseCorrectionHistogramsback to summary
private void swapPauseCorrectionHistograms()
swapRecordingHistogramsback to summary
private void swapRecordingHistograms()
trackRecordingIntervalback to summary
private void trackRecordingInterval()
updateHistogramsback to summary
private synchronized void updateHistograms()
org.LatencyUtils back to summary

public Class LatencyStats.Builder

extends Object
Class Inheritance

A fluent API builder class for creating LatencyStats objects.
Uses the following defaults:

Field Summary

Modifier and TypeField and Description
private long
private long
private int
private long
private int
private PauseDetector

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public LatencyStats
public static LatencyStats.Builder
public LatencyStats.Builder
highestTrackableLatency(long highestTrackableLatency)

public LatencyStats.Builder
intervalEstimatorTimeCap(long intervalEstimatorTimeCap)

public LatencyStats.Builder
intervalEstimatorWindowLength(int intervalEstimatorWindowLength)

public LatencyStats.Builder
lowestTrackableLatency(long lowestTrackableLatency)

public LatencyStats.Builder
numberOfSignificantValueDigits(int numberOfSignificantValueDigits)

public LatencyStats.Builder
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

highestTrackableLatencyback to summary
private long highestTrackableLatency
intervalEstimatorTimeCapback to summary
private long intervalEstimatorTimeCap
intervalEstimatorWindowLengthback to summary
private int intervalEstimatorWindowLength
lowestTrackableLatencyback to summary
private long lowestTrackableLatency
numberOfSignificantValueDigitsback to summary
private int numberOfSignificantValueDigits
pauseDetectorback to summary
private PauseDetector pauseDetector

Constructor Detail

Builderback to summary
public Builder()

Method Detail

buildback to summary
public LatencyStats build()
createback to summary
public static LatencyStats.Builder create()
highestTrackableLatencyback to summary
public LatencyStats.Builder highestTrackableLatency(long highestTrackableLatency)
intervalEstimatorTimeCapback to summary
public LatencyStats.Builder intervalEstimatorTimeCap(long intervalEstimatorTimeCap)
intervalEstimatorWindowLengthback to summary
public LatencyStats.Builder intervalEstimatorWindowLength(int intervalEstimatorWindowLength)
lowestTrackableLatencyback to summary
public LatencyStats.Builder lowestTrackableLatency(long lowestTrackableLatency)
numberOfSignificantValueDigitsback to summary
public LatencyStats.Builder numberOfSignificantValueDigits(int numberOfSignificantValueDigits)
pauseDetectorback to summary
public LatencyStats.Builder pauseDetector(PauseDetector pauseDetector)
org.LatencyUtils back to summary

private Class LatencyStats.PauseTracker

extends WeakReference<LatencyStats>
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
PauseTracker(final PauseDetector pauseDetector, final LatencyStats latencyStats)

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 LatencyStats latencyStats)

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()