uddsketch, but you can also choose to use tdigest.
Technically, a percentile divides a group into 100 equally sized pieces, while a quantile divides a
group into an arbitrary number of pieces. Because we don’t always use exactly 100 buckets,
“quantile” is the more technically correct term in this case. However, we use the word “percentile”
because it’s a more common word for this type of function.
Approximation algorithms
provides two algorithms for percentile approximation:uddsketch and tdigest.
Each algorithm has different features that make one better than another depending on your use case.
-
uddsketch: The default algorithm. It uses exponentially sized buckets to guarantee the approximation falls within a known error range, relative to the true discrete percentile. This algorithm offers the ability to tune the size and maximum error target of the sketch. Advantages:- Stable bucketing function that always returns the same percentile estimate for the same data, regardless of ordering or re-aggregation
- Guaranteed relative error bounds that are easier to characterize
- Smaller memory and disk footprint than
tdigest - Simpler to increase accuracy by adding more buckets
- Uses exponential bucketing, which can cause varying absolute errors if the dataset covers a large range. For example, if data is evenly distributed over [1,100], estimates at the high end have about 100 times the absolute error of those at the low end
- Provides discrete percentile estimates (using ‘s
percentile_discdefinition)
-
tdigest: Buckets data more aggressively toward the center of the quantile range, giving it greater accuracy at the tails of the range, around 0.001 or 0.995. Advantages:- Optimized for accurate estimates at the extremes (for example, ninety-ninth percentiles)
- More stable absolute error across the data range
- Provides continuous percentile estimates (using ‘s
percentile_contdefinition)
- Builds incremental buckets based on averages of nearby points, which can result in subtle differences in estimates unless order and batching are strictly controlled
- More difficult to calculate precise error bars, especially when merging multiple sub-digests
- Less accurate for median estimates compared to
uddsketch
uddsketch and tdigest:
- Percentile targets: Use
tdigestif you need accurate ninety-ninth percentiles. Useuddsketchfor accurate median estimates. - Stability requirements: Use
uddsketchif you need consistent estimates across different aggregation orders. - Error characterization: Use
uddsketchif you need well-defined error bounds. Usetdigestif you need stable absolute errors across large data ranges. - Memory constraints: Use
uddsketchfor smaller memory and disk footprints.
tdigest, the default uddsketch is your best choice.
Prerequisites
To follow the steps on this page:- Create a target with Real-time analytics enabled. You need your connection details. This procedure also works for .
Calculate percentiles
This example uses aresponse_times table that tracks how long a server takes to respond to API
calls.
-
Create the
response_timeshypertable -
Insert sample data
Generate response times with occasional slow responses to demonstrate percentile analysis:
-
Create a continuous aggregate with daily percentile aggregates
Use
percentile_agg()to create the aggregate: -
Query the ninety-fifth percentile over the last 30 days
Use
approx_percentile()androllup()to query the aggregated data: -
Create an alert for slow responses
Detect requests that exceed the ninety-fifth percentile threshold: