Class RateLimiterTokenBucket
- java.lang.Object
-
- software.amazon.awssdk.retries.internal.ratelimiter.RateLimiterTokenBucket
-
public class RateLimiterTokenBucket extends Object
TheRateLimiterTokenBucketkeeps 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 atryAcquire()call. Callers must update its internal state by callingupdateRateAfterThrottling()when getting a throttling response orupdateRateAfterSuccess()when getting successful response.This class is thread-safe, its internal current state is kept in the inner class
RateLimiterTokenBucket.PersistentStatewhich is stored using anAtomicReference. This class is converted toRateLimiterTokenBucket.TransientStatewhen the state needs to be mutated and converted back to aRateLimiterTokenBucket.PersistentStateand stored usingAtomicReference.compareAndSet(Object, Object).The algorithm used is adapted from the network congestion avoidance algorithm CUBIC.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RateLimiterAcquireResponsetryAcquire()Acquire tokens from the bucket.RateLimiterUpdateResponseupdateRateAfterSuccess()Updates the estimated send rate after a successful response.RateLimiterUpdateResponseupdateRateAfterThrottling()Updates the estimated send rate after a throttling response.
-
-
-
Method Detail
-
tryAcquire
public RateLimiterAcquireResponse tryAcquire()
Acquire tokens from the bucket. If the bucket contains enough capacity to satisfy the request, this method will return inRateLimiterAcquireResponse.delay()aDuration.ZEROvalue, otherwise it will return the amount of time the callers need to wait until enough tokens are refilled.
-
updateRateAfterThrottling
public RateLimiterUpdateResponse updateRateAfterThrottling()
Updates the estimated send rate after a throttling response.
-
updateRateAfterSuccess
public RateLimiterUpdateResponse updateRateAfterSuccess()
Updates the estimated send rate after a successful response.
-
-