Class PercentileTracker
- java.lang.Object
-
- com.datastax.driver.core.PercentileTracker
-
- All Implemented Interfaces:
LatencyTracker
- Direct Known Subclasses:
ClusterWidePercentileTracker,PerHostPercentileTracker
public abstract class PercentileTracker extends Object implements LatencyTracker
ALatencyTrackerthat 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} andPercentileSpeculativeExecutionPolicy.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPercentileTracker.Builder<B,T>Base class forPercentileTrackerimplementation builders.
-
Constructor Summary
Constructors Modifier Constructor Description protectedPercentileTracker(long highestTrackableLatencyMillis, int numberOfSignificantValueDigits, int minRecordedValues, long intervalMs)Builds a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract ObjectcomputeKey(Host host, Statement statement, Exception exception)Computes a key used to categorize measurements.longgetLatencyAtPercentile(Host host, Statement statement, Exception exception, double percentile)Returns the request latency at a given percentile.protected booleaninclude(Host host, Statement statement, Exception exception)Determines whether a particular measurement should be included.voidonRegister(Cluster cluster)Gets invoked when the tracker is registered with a cluster, or at cluster startup if the tracker was registered at initialization withCluster.register(LatencyTracker).voidonUnregister(Cluster cluster)Gets invoked when the tracker is unregistered from a cluster, or at cluster shutdown if the tracker was not unregistered.voidupdate(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.
-
-
-
Constructor Detail
-
PercentileTracker
protected PercentileTracker(long highestTrackableLatencyMillis, int numberOfSignificantValueDigits, int minRecordedValues, long intervalMs)Builds a new instance.- See Also:
PercentileTracker.Builder
-
-
Method Detail
-
computeKey
protected abstract Object computeKey(Host host, Statement statement, Exception exception)
Computes a key used to categorize measurements. Measurements with the same key will be recorded in the same histogram.It's recommended to keep the number of distinct keys low, in order to limit the memory footprint of the histograms.
- Parameters:
host- the host that was queried.statement- the statement that was executed.exception- if the query failed, the corresponding exception.- Returns:
- the key.
-
update
public void update(Host host, Statement statement, Exception exception, long newLatencyNanos)
Description copied from interface:LatencyTrackerA method that is called after each request to a Cassandra node with the duration of that operation.Note that there is no guarantee that this method won't be called concurrently by multiple threads, so implementations should synchronize internally if need be.
- Specified by:
updatein interfaceLatencyTracker- Parameters:
host- The Cassandra host on which a request has been performed. This parameter is nevernull.statement- TheStatementthat has been executed. This parameter is nevernull.exception- AnExceptionthrown when receiving the response, ornullif 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 tohostand when the response was received by the driver (or the operation timed out, in whichnewLatencyNanoswill approximately be the timeout value).
-
getLatencyAtPercentile
public long getLatencyAtPercentile(Host host, Statement statement, Exception exception, double percentile)
Returns the request latency at a given percentile.- Parameters:
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.0for the 99th percentile).- Returns:
- the latency (in milliseconds) at the given percentile, or a negative value if it's not available yet.
- See Also:
computeKey(Host, Statement, Exception)
-
onRegister
public void onRegister(Cluster cluster)
Description copied from interface:LatencyTrackerGets invoked when the tracker is registered with a cluster, or at cluster startup if the tracker was registered at initialization withCluster.register(LatencyTracker).- Specified by:
onRegisterin interfaceLatencyTracker- Parameters:
cluster- the cluster that this tracker is registered with.
-
onUnregister
public void onUnregister(Cluster cluster)
Description copied from interface:LatencyTrackerGets invoked when the tracker is unregistered from a cluster, or at cluster shutdown if the tracker was not unregistered.- Specified by:
onUnregisterin interfaceLatencyTracker- Parameters:
cluster- the cluster that this tracker was registered with.
-
include
protected boolean include(Host host, Statement statement, Exception exception)
Determines whether a particular measurement should be included.This is used to ignore measurements that could skew the statistics; for example, we typically want to ignore invalid query errors because they have a very low latency and would make a given cluster/host appear faster than it really is.
- Parameters:
host- the host that was queried.statement- the statement that was executed.exception- if the query failed, the corresponding exception.- Returns:
- whether the measurement should be included.
-
-