Class SmoothRateLimiter

java.lang.Object
com.google.common.util.concurrent.RateLimiter
com.google.common.util.concurrent.SmoothRateLimiter
Direct Known Subclasses:
SmoothRateLimiter.SmoothBursty, SmoothRateLimiter.SmoothWarmingUp

abstract class SmoothRateLimiter extends RateLimiter
  • Field Details

    • storedPermits

      double storedPermits
      The currently stored permits.
    • maxPermits

      double maxPermits
      The maximum number of stored permits.
    • stableIntervalMicros

      double stableIntervalMicros
      The interval between two unit requests, at our stable rate. E.g., a stable rate of 5 permits per second has a stable interval of 200ms.
    • nextFreeTicketMicros

      private long nextFreeTicketMicros
      The time when the next request (no matter its size) will be granted. After granting a request, this is pushed further in the future. Large requests push this further than small requests.
  • Constructor Details

  • Method Details

    • doSetRate

      final void doSetRate(double permitsPerSecond, long nowMicros)
      Specified by:
      doSetRate in class RateLimiter
    • doSetRate

      abstract void doSetRate(double permitsPerSecond, double stableIntervalMicros)
    • doGetRate

      final double doGetRate()
      Specified by:
      doGetRate in class RateLimiter
    • queryEarliestAvailable

      final long queryEarliestAvailable(long nowMicros)
      Description copied from class: RateLimiter
      Returns the earliest time that permits are available (with one caveat).
      Specified by:
      queryEarliestAvailable in class RateLimiter
      Returns:
      the time that permits are available, or, if permits are available immediately, an arbitrary past or present time
    • reserveEarliestAvailable

      final long reserveEarliestAvailable(int requiredPermits, long nowMicros)
      Description copied from class: RateLimiter
      Reserves the requested number of permits and returns the time that those permits can be used (with one caveat).
      Specified by:
      reserveEarliestAvailable in class RateLimiter
      Returns:
      the time that the permits may be used, or, if the permits may be used immediately, an arbitrary past or present time
    • storedPermitsToWaitTime

      abstract long storedPermitsToWaitTime(double storedPermits, double permitsToTake)
      Translates a specified portion of our currently stored permits which we want to spend/acquire, into a throttling time. Conceptually, this evaluates the integral of the underlying function we use, for the range of [(storedPermits - permitsToTake), storedPermits].

      This always holds: 0 <= permitsToTake <= storedPermits

    • coolDownIntervalMicros

      abstract double coolDownIntervalMicros()
      Returns the number of microseconds during cool down that we have to wait to get a new permit.
    • resync

      void resync(long nowMicros)
      Updates storedPermits and nextFreeTicketMicros based on the current time.