Class SampleQuantiles

java.lang.Object
org.apache.hadoop.metrics2.util.SampleQuantiles
All Implemented Interfaces:
QuantileEstimator

@Private public class SampleQuantiles extends Object implements QuantileEstimator
Implementation of the Cormode, Korn, Muthukrishnan, and Srivastava algorithm for streaming calculation of targeted high-percentile epsilon-approximate quantiles. This is a generalization of the earlier work by Greenwald and Khanna (GK), which essentially allows different error bounds on the targeted quantiles, which allows for far more efficient calculation of high-percentiles. See: Cormode, Korn, Muthukrishnan, and Srivastava "Effective Computation of Biased Quantiles over Data Streams" in ICDE 2005 Greenwald and Khanna, "Space-efficient online computation of quantile summaries" in SIGMOD 2001
  • Constructor Details

    • SampleQuantiles

      public SampleQuantiles(Quantile[] quantiles)
  • Method Details

    • insert

      public void insert(long v)
      Add a new value from the stream.
      Specified by:
      insert in interface QuantileEstimator
      Parameters:
      v - v.
    • snapshot

      public Map<Quantile,Long> snapshot()
      Get a snapshot of the current values of all the tracked quantiles.
      Specified by:
      snapshot in interface QuantileEstimator
      Returns:
      snapshot of the tracked quantiles. If no items are added to the estimator, returns null.
    • getCount

      public long getCount()
      Returns the number of items that the estimator has processed
      Specified by:
      getCount in interface QuantileEstimator
      Returns:
      count total number of items processed
    • getSampleCount

      @VisibleForTesting public int getSampleCount()
      Returns the number of samples kept by the estimator
      Returns:
      count current number of samples
    • clear

      public void clear()
      Resets the estimator, clearing out all previously inserted items
      Specified by:
      clear in interface QuantileEstimator
    • toString

      public String toString()
      Overrides:
      toString in class Object