DoubleHistogram samples from live recorded data without interrupting or stalling active recording
of values. Each interval histogram provided contains all value counts accumulated since the
previous interval histogram was taken.
This pattern is commonly used in logging interval histogram information while recording is ongoing.
DoubleRecorder supports concurrent
DoubleRecorder#recordValue or
DoubleRecorder#recordValueWithExpectedInterval calls.
Recording calls are wait-free on architectures that support atomic increment operations, and
are lock-free on architectures that do not.
A common pattern for using a DoubleRecorder looks like this:
DoubleRecorder recorder = new DoubleRecorder(2); // Two decimal point accuracy
DoubleHistogram intervalHistogram = null;
...
[start of some loop construct that periodically wants to grab an interval histogram]
...
// Get interval histogram, recycling previous interval histogram:
intervalHistogram = recorder.getIntervalHistogram(intervalHistogram);
histogramLogWriter.outputIntervalHistogram(intervalHistogram);
...
[end of loop construct]
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private volatile ConcurrentDoubleHistogram | |
| private ConcurrentDoubleHistogram | |
| private final long | |
| private static AtomicLong | |
| private final WriterReaderPhaser |
| Access | Constructor and Description |
|---|---|
| public | DoubleRecorder(final int
Specifies the precision to use. This is the number of significant
decimal digits to which the histogram will maintain value resolution
and separation. Must be a non-negative integer between 0 and 5. numberOfSignificantValueDigits, boolean Specifies whether the recorder will uses a packed internal representation or not. packed)Construct an auto-resizing |
| public | DoubleRecorder(final int
Specifies the precision to use. This is the number of significant
decimal digits to which the histogram will maintain value resolution
and separation. Must be a non-negative integer between 0 and 5. numberOfSignificantValueDigits)Construct an auto-resizing |
| public | DoubleRecorder(final long
specifies the dynamic range to use (as a ratio) highestToLowestValueRatio, final int Specifies the precision to use. This is the number of significant
decimal digits to which the histogram will maintain value resolution
and separation. Must be a non-negative integer between 0 and 5. numberOfSignificantValueDigits)Construct a |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized DoubleHistogram | Returns: a histogram containing the value counts accumulated since the last interval histogram was taken.Get a new instance of an interval histogram, which will include a stable, consistent view of all value counts accumulated since the last interval histogram was taken. |
| public synchronized DoubleHistogram | Returns: a histogram containing the value counts accumulated since the last interval histogram was taken.a previously returned interval histogram (from this instance of
histogramToRecycle)DoubleRecorder) that may be recycled to avoid allocation and
copy operations.Get an interval histogram, which will include a stable, consistent view of all value counts accumulated since the last interval histogram was taken. |
| public synchronized DoubleHistogram | Returns: a histogram containing the value counts accumulated since the last interval histogram was taken.a previously returned interval histogram that may be recycled to avoid allocation and
copy operations. histogramToRecycle, boolean if true, will only allow recycling of histograms previously returned from this
instance of enforeContainingInstance)DoubleRecorder. If false, will allow recycling histograms
previously returned by other instances of DoubleRecorder.Get an interval histogram, which will include a stable, consistent view of all value counts accumulated since the last interval histogram was taken. |
| public synchronized void | getIntervalHistogramInto(DoubleHistogram
the histogram into which the interval histogram's data should be copied targetHistogram)Place a copy of the value counts accumulated since accumulated (since the last interval histogram
was taken) into |
| private void | |
| public void | recordValue(final double
the value to record value)Implements org. |
| public void | recordValueWithCount(final double
The value to be recorded value, final long The number of occurrences of this value to record count)Implements org. |
| public void | recordValueWithExpectedInterval(final double
The value to record value, final double If expectedIntervalBetweenValueSamples is larger than 0, add
auto-generated value records as appropriate if value is larger
than expectedIntervalBetweenValueSamples expectedIntervalBetweenValueSamples)Implements org. To compensate for the loss of sampled values when a recorded value is larger than the expected interval between value samples, Histogram will auto-generate an additional series of decreasingly-smaller (down to the expectedIntervalBetweenValueSamples) value records. |
| public synchronized void | reset()
Implements org. |
| private void | validateFitAsReplacementHistogram(DoubleHistogram replacementHistogram, boolean enforeContainingInstance)
|
| activeHistogram | back to summary |
|---|---|
| private volatile ConcurrentDoubleHistogram activeHistogram | |
| inactiveHistogram | back to summary |
|---|---|
| private ConcurrentDoubleHistogram inactiveHistogram | |
| instanceId | back to summary |
|---|---|
| private final long instanceId | |
| instanceIdSequencer | back to summary |
|---|---|
| private static AtomicLong instanceIdSequencer | |
| recordingPhaser | back to summary |
|---|---|
| private final WriterReaderPhaser recordingPhaser | |
| DoubleRecorder | back to summary |
|---|---|
| public DoubleRecorder(final int numberOfSignificantValueDigits, boolean packed) Construct an auto-resizing
Depending on the valuer of the
| |
| DoubleRecorder | back to summary |
|---|---|
| public DoubleRecorder(final int numberOfSignificantValueDigits) Construct an auto-resizing
| |
| DoubleRecorder | back to summary |
|---|---|
| public DoubleRecorder(final long highestToLowestValueRatio, final int numberOfSignificantValueDigits) Construct a
| |
| getIntervalHistogram | back to summary |
|---|---|
| public synchronized DoubleHistogram getIntervalHistogram() Get a new instance of an interval histogram, which will include a stable, consistent view of all value counts accumulated since the last interval histogram was taken.
Calling
| |
| getIntervalHistogram | back to summary |
|---|---|
| public synchronized DoubleHistogram getIntervalHistogram(DoubleHistogram histogramToRecycle) Get an interval histogram, which will include a stable, consistent view of all value counts accumulated since the last interval histogram was taken.
Note The caller is responsible for not recycling the same returned interval histogram more than once. If the same interval histogram instance is recycled more than once, behavior is undefined.
Calling
| |
| getIntervalHistogram | back to summary |
|---|---|
| public synchronized DoubleHistogram getIntervalHistogram(DoubleHistogram histogramToRecycle, boolean enforeContainingInstance) Get an interval histogram, which will include a stable, consistent view of all value counts accumulated since the last interval histogram was taken.
Note The caller is responsible for not recycling the same returned interval histogram more than once. If the same interval histogram instance is recycled more than once, behavior is undefined.
Calling
| |
| getIntervalHistogramInto | back to summary |
|---|---|
| public synchronized void getIntervalHistogramInto(DoubleHistogram targetHistogram) Place a copy of the value counts accumulated since accumulated (since the last interval histogram
was taken) into
| |
| performIntervalSample | back to summary |
|---|---|
| private void performIntervalSample() | |
| recordValue | back to summary |
|---|---|
| public void recordValue(final double value) Implements org. Record a value
| |
| recordValueWithCount | back to summary |
|---|---|
| public void recordValueWithCount(final double value, final long count) throws ArrayIndexOutOfBoundsException Implements org. Record a value in the histogram (adding to the value's current count)
| |
| recordValueWithExpectedInterval | back to summary |
|---|---|
| public void recordValueWithExpectedInterval(final double value, final double expectedIntervalBetweenValueSamples) throws ArrayIndexOutOfBoundsException Implements org. Record a value To compensate for the loss of sampled values when a recorded value is larger than the expected interval between value samples, Histogram will auto-generate an additional series of decreasingly-smaller (down to the expectedIntervalBetweenValueSamples) value records.
See related notes
| |
| reset | back to summary |
|---|---|
| public synchronized void reset() Implements org. Reset any value counts accumulated thus far.
| |
| validateFitAsReplacementHistogram | back to summary |
|---|---|
| private void validateFitAsReplacementHistogram(DoubleHistogram replacementHistogram, boolean enforeContainingInstance) | |
| Modifier and Type | Field and Description |
|---|---|
| private final long |
| Access | Constructor and Description |
|---|---|
| private | |
| private | InternalConcurrentDoubleHistogram(long id, long highestToLowestValueRatio, int numberOfSignificantValueDigits)
|
| private |
| containingInstanceId | back to summary |
|---|---|
| private final long containingInstanceId | |
| InternalConcurrentDoubleHistogram | back to summary |
|---|---|
| private InternalConcurrentDoubleHistogram(long id, int numberOfSignificantValueDigits) | |
| InternalConcurrentDoubleHistogram | back to summary |
|---|---|
| private InternalConcurrentDoubleHistogram(long id, long highestToLowestValueRatio, int numberOfSignificantValueDigits) | |
| InternalConcurrentDoubleHistogram | back to summary |
|---|---|
| private InternalConcurrentDoubleHistogram(DoubleRecorder. | |
| Modifier and Type | Field and Description |
|---|---|
| private final long |
| Access | Constructor and Description |
|---|---|
| private |
| containingInstanceId | back to summary |
|---|---|
| private final long containingInstanceId | |
| PackedInternalConcurrentDoubleHistogram | back to summary |
|---|---|
| private PackedInternalConcurrentDoubleHistogram(long id, int numberOfSignificantValueDigits) | |