Class RateLimiterTokenBucket
java.lang.Object
software.amazon.awssdk.retries.internal.ratelimiter.RateLimiterTokenBucket
The
RateLimiterTokenBucket
keeps track of past throttling responses and adapts to slow down the send rate to adapt to
the service. It does this by suggesting a delay amount as result of a tryAcquire()
call. Callers must update its
internal state by calling updateRateAfterThrottling()
when getting a throttling response or
updateRateAfterSuccess()
when getting successful response.
This class is thread-safe, its internal current state is kept in the inner class RateLimiterTokenBucket.PersistentState
which is stored
using an AtomicReference
. This class is converted to RateLimiterTokenBucket.TransientState
when the state needs to be mutated and
converted back to a RateLimiterTokenBucket.PersistentState
and stored using AtomicReference.compareAndSet(Object, Object)
.
The algorithm used is adapted from the network congestion avoidance algorithm CUBIC.
-
Method Summary
Modifier and TypeMethodDescriptionAcquire tokens from the bucket.Updates the estimated send rate after a successful response.Updates the estimated send rate after a throttling response.
-
Method Details
-
tryAcquire
Acquire tokens from the bucket. If the bucket contains enough capacity to satisfy the request, this method will return inRateLimiterAcquireResponse.delay()
aDuration.ZERO
value, otherwise it will return the amount of time the callers need to wait until enough tokens are refilled. -
updateRateAfterThrottling
Updates the estimated send rate after a throttling response. -
updateRateAfterSuccess
Updates the estimated send rate after a successful response.
-