public final class PercentileTimer extends Object implements Timer
Percentile timers are expensive compared to basic timers from the registry. In
particular they have a higher storage cost, worst case ~300x, to maintain the data
distribution. Be diligent about any additional dimensions added to percentile timers and
ensure they have a small bounded cardinality. In addition it is highly recommended to
set a range (see PercentileTimer.Builder.withRange(long, long, TimeUnit)) whenever possible to
greatly restrict the worst case overhead.
When using the builder (builder(Registry)), the range will default from 10 ms
to 1 minute. Based on data at Netflix this is the most common range for request latencies
and restricting to this window reduces the worst case multiple from 276 to 58
| Modifier and Type | Class and Description |
|---|---|
static class |
PercentileTimer.Builder
Helper for getting instances of a PercentileTimer.
|
| Modifier and Type | Method and Description |
|---|---|
static IdBuilder<PercentileTimer.Builder> |
builder(Registry registry)
Return a builder for configuring and retrieving and instance of a percentile timer.
|
long |
count()
The number of times that record has been called since this timer was last reset.
|
static PercentileTimer |
get(Registry registry,
Id id)
Creates a timer object that can be used for estimating percentiles.
|
boolean |
hasExpired()
Indicates whether the meter is expired.
|
Id |
id()
Identifier used to lookup this meter in the registry.
|
Iterable<Measurement> |
measure()
Get the set of measurements for this meter.
|
double |
percentile(double p)
Computes the specified percentile for this timer.
|
<T> T |
record(Callable<T> rf)
Executes the callable `f` and records the time taken.
|
void |
record(long amount,
TimeUnit unit)
Updates the statistics kept by the counter with the specified amount.
|
void |
record(Runnable rf)
Executes the runnable `f` and records the time taken.
|
long |
totalTime()
The total time in nanoseconds of all recorded events since this timer was last reset.
|
public static PercentileTimer get(Registry registry, Id id)
PercentileTimer.Builder.withRange(long, long, TimeUnit)) whenever possible.registry - Registry to use.id - Identifier for the metric being registered.public static IdBuilder<PercentileTimer.Builder> builder(Registry registry)
public Id id()
Meterpublic Iterable<Measurement> measure()
Meterpublic boolean hasExpired()
MeterhasExpired in interface Meterpublic void record(long amount,
TimeUnit unit)
Timerpublic <T> T record(Callable<T> rf) throws Exception
Timerpublic void record(Runnable rf)
Timerpublic double percentile(double p)
p - Percentile to compute, value must be 0.0 <= p <= 100.0.p`th percentile in seconds.public long count()
Timer