Class AdaptiveThrottler

java.lang.Object
org.apache.beam.sdk.io.components.throttling.AdaptiveThrottler
Direct Known Subclasses:
ReactiveThrottler

public class AdaptiveThrottler extends Object
Implements adaptive throttling.

See https://landing.google.com/sre/book/chapters/handling-overload.html#client-side-throttling-a7sYUg for a full discussion of the use case and algorithm applied.

  • Field Details

  • Constructor Details

    • AdaptiveThrottler

      public AdaptiveThrottler(long samplePeriodMs, long sampleUpdateMs, double overloadRatio)
      Initializes AdaptiveThrottler.
      Parameters:
      samplePeriodMs - length of history to consider, in ms, to set throttling.
      sampleUpdateMs - granularity of time buckets that we store data in, in ms.
      overloadRatio - the target ratio between requests sent and successful requests.
  • Method Details

    • throttlingProbability

      protected double throttlingProbability(long nowMsSinceEpoch)
    • throttleRequest

      public boolean throttleRequest(long nowMsSinceEpoch)
      Determines whether one RPC attempt should be throttled.

      This should be called once each time the caller intends to send an RPC; if it returns true, drop or delay that request (calling this function again after the delay).

      Parameters:
      nowMsSinceEpoch - time in ms since the epoch
      Returns:
      true if the caller should throttle or delay the request.
    • successfulRequest

      public void successfulRequest(long nowMsSinceEpoch)
      Notifies the throttler of a successful request.

      Must be called once for each request (for which throttleRequest was previously called) that succeeded.

      Parameters:
      nowMsSinceEpoch - time in ms since the epoch