public abstract class PercentileTracker extends Object implements LatencyTracker
LatencyTracker
that records query latencies over a sliding time interval, and exposes an API to retrieve
the latency at a given percentile.
Percentiles may be computed separately for different categories of requests; this is implementation-dependent and
determined by computeKey(Host, Statement, Exception)
.
This class is used by percentile-aware components such as
QueryLogger.Builder.withDynamicThreshold(PercentileTracker, double)
QueryLogger} and
PercentileSpeculativeExecutionPolicy
.
It uses HdrHistogram to record latencies:
for each category, there is a "live" histogram where current latencies are recorded, and a "cached", read-only
histogram that is used when clients call getLatencyAtPercentile(Host, Statement, Exception, double)
. Each
time the cached histogram becomes older than the interval, the two histograms are switched. Statistics will not be
available during the first interval at cluster startup, since we don't have a cached histogram yet.Modifier and Type | Class and Description |
---|---|
static class |
PercentileTracker.Builder<B,T>
Base class for
PercentileTracker implementation builders. |
Modifier | Constructor and Description |
---|---|
protected |
PercentileTracker(long highestTrackableLatencyMillis,
int numberOfSignificantValueDigits,
int minRecordedValues,
long intervalMs)
Builds a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected abstract Object |
computeKey(Host host,
Statement statement,
Exception exception)
Computes a key used to categorize measurements.
|
long |
getLatencyAtPercentile(Host host,
Statement statement,
Exception exception,
double percentile)
Returns the request latency at a given percentile.
|
protected boolean |
include(Host host,
Statement statement,
Exception exception)
Determines whether a particular measurement should be included.
|
void |
onRegister(Cluster cluster)
Gets invoked when the tracker is registered with a cluster, or at cluster startup if the
tracker was registered at initialization with
Cluster.register(LatencyTracker) . |
void |
onUnregister(Cluster cluster)
Gets invoked when the tracker is unregistered from a cluster, or at cluster shutdown if
the tracker was not unregistered.
|
void |
update(Host host,
Statement statement,
Exception exception,
long newLatencyNanos)
A method that is called after each request to a Cassandra node with
the duration of that operation.
|
protected PercentileTracker(long highestTrackableLatencyMillis, int numberOfSignificantValueDigits, int minRecordedValues, long intervalMs)
PercentileTracker.Builder
protected abstract Object computeKey(Host host, Statement statement, Exception exception)
host
- the host that was queried.statement
- the statement that was executed.exception
- if the query failed, the corresponding exception.public void update(Host host, Statement statement, Exception exception, long newLatencyNanos)
LatencyTracker
update
in interface LatencyTracker
host
- The Cassandra host on which a request has been performed.
This parameter is never null
.statement
- The Statement
that has been executed.
This parameter is never null
.exception
- An Exception
thrown when receiving the response, or null
if the response was successful.newLatencyNanos
- the latency in nanoseconds of the operation.
This latency corresponds to the time elapsed between
when the query was sent to host
and
when the response was received by the driver
(or the operation timed out, in which newLatencyNanos
will approximately be the timeout value).public long getLatencyAtPercentile(Host host, Statement statement, Exception exception, double percentile)
host
- the host (if this is relevant in the way percentiles are categorized).statement
- the statement (if this is relevant in the way percentiles are categorized).exception
- the exception (if this is relevant in the way percentiles are categorized).percentile
- the percentile (for example, 99.0
for the 99th percentile).computeKey(Host, Statement, Exception)
public void onRegister(Cluster cluster)
LatencyTracker
Cluster.register(LatencyTracker)
.onRegister
in interface LatencyTracker
cluster
- the cluster that this tracker is registered with.public void onUnregister(Cluster cluster)
LatencyTracker
onUnregister
in interface LatencyTracker
cluster
- the cluster that this tracker was registered with.protected boolean include(Host host, Statement statement, Exception exception)
host
- the host that was queried.statement
- the statement that was executed.exception
- if the query failed, the corresponding exception.