Class AdaptiveBackoff
java.lang.Object
com.cockroachlabs.crdb.retry.AdaptiveBackoff
Computes backoff delays that adapt to observed contention.
The engine keeps a short rolling window of how many retries recent
operations actually needed. When contention is high the base delay is
lengthened (up to RetryPolicy.maxDelayMillis()); when the cluster is
calm it shrinks back toward RetryPolicy.baseDelayMillis(). Jitter is
drawn from an injectable DoubleSupplier, so the class is fully
deterministic under test.
Not thread-safe on its own; the retry engine synchronizes access.
-
Constructor Summary
ConstructorsConstructorDescriptionAdaptiveBackoff(RetryPolicy policy) UsesThreadLocalRandomfor jitter.AdaptiveBackoff(RetryPolicy policy, DoubleSupplier jitterSource) -
Method Summary
Modifier and TypeMethodDescriptiondoubleContention estimate in [0, 1]: recent average retries relative to the policy'smaxRetries.longnextDelayMillis(int attempt) The delay to wait before the given zero-basedattempt.voidrecord(int retriesUsed) Feed the observed number of retries an operation needed.
-
Constructor Details
-
AdaptiveBackoff
UsesThreadLocalRandomfor jitter. -
AdaptiveBackoff
- Parameters:
policy- the retry policy driving base/max/multiplier/jitterjitterSource- supplies values in [0, 1); inject for deterministic tests
-
-
Method Details
-
record
public void record(int retriesUsed) Feed the observed number of retries an operation needed. Drives the adaptive contention estimate. -
contentionRatio
public double contentionRatio()Contention estimate in [0, 1]: recent average retries relative to the policy'smaxRetries. -
nextDelayMillis
public long nextDelayMillis(int attempt) The delay to wait before the given zero-basedattempt. Guaranteed to lie within[0, maxDelayMillis], and (with zero jitter) to be non-decreasing inattempt.
-