Class RateLimiterTokenBucket
java.lang.Object
software.amazon.awssdk.retries.internal.ratelimiter.RateLimiterTokenBucket
- All Implemented Interfaces:
AutoCloseable,SdkAutoCloseable
@SdkInternalApi
@ThreadSafe
public class RateLimiterTokenBucket
extends Object
implements SdkAutoCloseable
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 delaying the completion of the future returned by acquireAsync() until the requested
capacity is available. 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.
The algorithm used is adapted from the network congestion avoidance algorithm CUBIC.
-
Method Summary
Modifier and TypeMethodDescriptionAcquire a token from the bucket.voidclose()Updates the estimated send rate after a successful response.Updates the estimated send rate after a throttling response.
-
Method Details
-
close
public void close()Description copied from interface:SdkAutoCloseable- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSdkAutoCloseable
-
acquireAsync
Acquire a token from the bucket.- Returns:
- A future that is completed when the requested amount is acquired from this bucket.
-
updateRateAfterThrottling
Updates the estimated send rate after a throttling response. -
updateRateAfterSuccess
Updates the estimated send rate after a successful response.
-