Class ExponentialBucketHistogram

java.lang.Object
org.elasticsearch.common.metrics.ExponentialBucketHistogram
Direct Known Subclasses:
HandlingTimeTracker

public class ExponentialBucketHistogram extends Object
A histogram with a fixed number of buckets of exponentially increasing width.

The bucket boundaries are defined by increasing powers of two, e.g. (-∞, 1), [1, 2), [2, 4), [4, 8), ..., [2^(bucketCount-2), ∞) There are bucketCount buckets.

  • Constructor Details

    • ExponentialBucketHistogram

      public ExponentialBucketHistogram(int bucketCount)
  • Method Details

    • getBucketUpperBounds

      public static int[] getBucketUpperBounds(int bucketCount)
    • calculateBucketUpperBounds

      public int[] calculateBucketUpperBounds()
    • addObservation

      public void addObservation(long observedValue)
    • getSnapshot

      public long[] getSnapshot()
      Returns:
      An array of frequencies of handling times in buckets with upper bounds as returned by calculateBucketUpperBounds(), plus an extra bucket for handling times longer than the longest upper bound.
    • getPercentile

      public long getPercentile(float percentile)
      Calculate the Nth percentile value
      Parameters:
      percentile - The percentile as a fraction (in [0, 1.0])
      Returns:
      A value greater than the specified fraction of values in the histogram
      Throws:
      IllegalArgumentException - if the requested percentile is invalid
    • getPercentile

      public long getPercentile(float percentile, long[] snapshot, int[] bucketUpperBounds)
      Calculate the Nth percentile value
      Parameters:
      percentile - The percentile as a fraction (in [0, 1.0])
      snapshot - An array of frequencies of handling times in buckets with upper bounds as per calculateBucketUpperBounds()
      bucketUpperBounds - The upper bounds of the buckets in the histogram, as per calculateBucketUpperBounds()
      Returns:
      A value greater than the specified fraction of values in the histogram
      Throws:
      IllegalArgumentException - if the requested percentile is invalid
    • clear

      public void clear()
      Clear all values in the histogram (non-atomic)