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 Details

    • close

      public void close()
      Description copied from interface: SdkAutoCloseable
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SdkAutoCloseable
    • acquireAsync

      public CompletableFuture<Void> acquireAsync()
      Acquire a token from the bucket.
      Returns:
      A future that is completed when the requested amount is acquired from this bucket.
    • 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.