public static class LatencyAwarePolicy.Builder extends Object
This helper allows to configure the different parameters used by
The only mandatory parameter is the child policy that will be wrapped with latency awareness.
The other parameters can be set through the methods of this builder, but all have defaults
(that are documented in the javadoc of each method) if you don't.
If you observe that the resulting policy excludes hosts too aggressively or not enough so,
the main parameters to check are the exclusion threshold (
|Modifier and Type||Field and Description|
|Constructor and Description|
Creates a new latency aware policy builder given the child policy that the resulting policy wraps.
|Modifier and Type||Method and Description|
Builds a new latency aware policy using the options set on this builder.
Sets the exclusion threshold to use for the resulting latency aware policy.
Sets the minimum number of measurements per-host to consider for the resulting latency aware policy.
Sets the retry period for the resulting latency aware policy.
Sets the scale to use for the resulting latency aware policy.
Sets the update rate for the resulting latency aware policy.
public static final double DEFAULT_EXCLUSION_THRESHOLD
public static final long DEFAULT_SCALE_NANOS
public static final long DEFAULT_RETRY_PERIOD_NANOS
public static final long DEFAULT_UPDATE_RATE_NANOS
public static final int DEFAULT_MIN_MEASURE
public Builder(LoadBalancingPolicy childPolicy)
childPolicy- the load balancing policy to wrap with latency awareness.
public LatencyAwarePolicy.Builder withExclusionThreshold(double exclusionThreshold)
The exclusion threshold controls how much worse the average latency of a node must be compared to the fastest performing node for it to be penalized by the policy.
The default exclusion threshold (if this method is not called) is 2. In other words, the resulting policy excludes nodes that are more than twice slower than the fastest node.
exclusionThreshold- the exclusion threshold to use. Must be greater or equal to 1.
exclusionThreshold < 1.
public LatencyAwarePolicy.Builder withScale(long scale, TimeUnit unit)
scale provides control on how the weight given to older latencies decreases
over time. For a given host, if a new latency
l is received at time
the previously calculated average is
prev calculated at time
t', then the
newly calculated average
avg for that host is calculated thusly:
Typically, with a
d = (t - t') / scale alpha = 1 - (ln(d+1) / d) avg = alpha * l + (1 - alpha * prev)
scaleof 100 milliseconds (the default), if a new latency is measured and the previous measure is 10 millisecond old (so
alphawill be around
0.05. In other words, the new latency will weight 5% of the updated average. A bigger scale will get less weight to new measurements (compared to previous ones), a smaller one will give them more weight.
The default scale (if this method is not used) is of 100 milliseconds. If unsure, try this default scale first and experiment only if it doesn't provide acceptable results (hosts are excluded too quickly or not fast enough and tuning the exclusion threshold doesn't help).
scale- the scale to use.
unit- the unit of
scale <= 0.
public LatencyAwarePolicy.Builder withRetryPeriod(long retryPeriod, TimeUnit unit)
The retry period defines how long a node may be penalized by the policy before it is given
a 2nd change. More precisely, a node is excluded from query plans if both his calculated
average latency is
exclusionThreshold times slower than the fastest node average
latency (at the time the query plan is computed) and his calculated average latency
has been updated since less than
retryPeriod. Since penalized nodes will likely not
see their latency updated, this is basically how long the policy will exclude a node.
retryPeriod- the retry period to use.
unit- the unit for
retryPeriod < 0.
public LatencyAwarePolicy.Builder withUpdateRate(long updateRate, TimeUnit unit)
The update rate defines how often the minimum average latency is recomputed. While the average latency score of each node is computed iteratively (updated each time a new latency is collected), the minimum score needs to be recomputed from scratch every time, which is slightly more costly. For this reason, the minimum is only re-calculated at the given fixed rate and cached between re-calculation.
The default update rate if 100 milliseconds, which should be appropriate for most applications. In particular, note that while we want to avoid to recompute the minimum for every query, that computation is not particularly intensive either and there is no reason to use a very slow rate (more than second is probably unnecessarily slow for instance).
updateRate- the update rate to use.
unit- the unit for
updateRate <e; 0.
public LatencyAwarePolicy.Builder withMininumMeasurements(int minMeasure)
Penalizing nodes is based on an average of their recently measured average latency. This
average is only meaningful if a minimum of measurements have been collected (moreover, a
newly started Cassandra node will tend to perform relatively poorly on the first queries due
to the JVM warmup). This is what this option controls. If less that
points have been collected for a given host, the policy will never penalize that host. Also,
the 30% first measurement will be entirely ignored (in other words, the
minMeasure first measurement to a node are entirely ignored, while the
70% next ones
are accounted in the latency computed but the node won't get convicted until we've had at
Note that the number of collected measurements for a given host is reset if the node is restarted.
The default for this option (if this method is not called) is 50. Note that it is probably not a good idea to put this option too low if only to avoid the influence of JVM warm-up on newly restarted nodes.
minMeasure- the minimum measurements to consider.
minMeasure < 0.
public LatencyAwarePolicy build()
Copyright © 2012–2020. All rights reserved.