Class SingleWriterRecorder

  • All Implemented Interfaces:
    IntervalHistogramProvider<Histogram>, ValueRecorder

    public class SingleWriterRecorder
    extends Object
    implements ValueRecorder, IntervalHistogramProvider<Histogram>
    Records integer values, and provides stable interval Histogram 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.

    SingleWriterRecorder expects only a single thread (the "single writer") to call recordValue(long) or recordValueWithExpectedInterval(long, long) at any point in time. It DOES NOT safely support concurrent recording calls. Recording calls are wait-free on architectures that support atomic increment operations, and re lock-free on architectures that do not. *

    A common pattern for using a SingleWriterRecorder looks like this:

    
     SingleWriterRecorder recorder = new SingleWriterRecorder(2); // Two decimal point accuracy
     Histogram 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]
     
    • Constructor Detail

      • SingleWriterRecorder

        public SingleWriterRecorder​(int numberOfSignificantValueDigits,
                                    boolean packed)
        Construct an auto-resizing SingleWriterRecorder with a lowest discernible value of 1 and an auto-adjusting highestTrackableValue. Can auto-resize up to track values up to (Long.MAX_VALUE / 2).

        Depending on the valuer of the packed parameter SingleWriterRecorder can be configured to track value counts in a packed internal representation optimized for typical histogram recoded values are sparse in the value range and tend to be incremented in small unit counts. This packed representation tends to require significantly smaller amounts of storage when compared to unpacked representations, but can incur additional recording cost due to resizing and repacking operations that may occur as previously unrecorded values are encountered.

        Parameters:
        numberOfSignificantValueDigits - 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.
        packed - Specifies whether the recorder will uses a packed internal representation or not.
      • SingleWriterRecorder

        public SingleWriterRecorder​(int numberOfSignificantValueDigits)
        Construct an auto-resizing SingleWriterRecorder with a lowest discernible value of 1 and an auto-adjusting highestTrackableValue. Can auto-resize up to track values up to (Long.MAX_VALUE / 2).
        Parameters:
        numberOfSignificantValueDigits - 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.
      • SingleWriterRecorder

        public SingleWriterRecorder​(long highestTrackableValue,
                                    int numberOfSignificantValueDigits)
        Construct a SingleWriterRecorder given the highest value to be tracked and a number of significant decimal digits. The histogram will be constructed to implicitly track (distinguish from 0) values as low as 1.
        Parameters:
        highestTrackableValue - The highest value to be tracked by the histogram. Must be a positive integer that is >= 2.
        numberOfSignificantValueDigits - 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.
      • SingleWriterRecorder

        public SingleWriterRecorder​(long lowestDiscernibleValue,
                                    long highestTrackableValue,
                                    int numberOfSignificantValueDigits)
        Construct a SingleWriterRecorder given the Lowest and highest values to be tracked and a number of significant decimal digits. Providing a lowestDiscernibleValue is useful is situations where the units used for the histogram's values are much smaller that the minimal accuracy required. E.g. when tracking time values stated in nanosecond units, where the minimal accuracy required is a microsecond, the proper value for lowestDiscernibleValue would be 1000.
        Parameters:
        lowestDiscernibleValue - The lowest value that can be tracked (distinguished from 0) by the histogram. Must be a positive integer that is >= 1. May be internally rounded down to nearest power of 2.
        highestTrackableValue - The highest value to be tracked by the histogram. Must be a positive integer that is >= (2 * lowestDiscernibleValue).
        numberOfSignificantValueDigits - 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.