Class SmoothRateLimiter
- java.lang.Object
-
- com.google.common.util.concurrent.RateLimiter
-
- com.google.common.util.concurrent.SmoothRateLimiter
-
- Direct Known Subclasses:
SmoothRateLimiter.SmoothBursty
,SmoothRateLimiter.SmoothWarmingUp
@GwtIncompatible abstract class SmoothRateLimiter extends RateLimiter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
SmoothRateLimiter.SmoothBursty
This implements a "bursty" RateLimiter, where storedPermits are translated to zero throttling.(package private) static class
SmoothRateLimiter.SmoothWarmingUp
This implements the following function where coldInterval = coldFactor * stableInterval.-
Nested classes/interfaces inherited from class com.google.common.util.concurrent.RateLimiter
RateLimiter.SleepingStopwatch
-
-
Field Summary
Fields Modifier and Type Field Description (package private) double
maxPermits
The maximum number of stored permits.private long
nextFreeTicketMicros
The time when the next request (no matter its size) will be granted.(package private) double
stableIntervalMicros
The interval between two unit requests, at our stable rate.(package private) double
storedPermits
The currently stored permits.
-
Constructor Summary
Constructors Modifier Constructor Description private
SmoothRateLimiter(RateLimiter.SleepingStopwatch stopwatch)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) abstract double
coolDownIntervalMicros()
Returns the number of microseconds during cool down that we have to wait to get a new permit.(package private) double
doGetRate()
(package private) abstract void
doSetRate(double permitsPerSecond, double stableIntervalMicros)
(package private) void
doSetRate(double permitsPerSecond, long nowMicros)
(package private) long
queryEarliestAvailable(long nowMicros)
Returns the earliest time that permits are available (with one caveat).(package private) long
reserveEarliestAvailable(int requiredPermits, long nowMicros)
Reserves the requested number of permits and returns the time that those permits can be used (with one caveat).(package private) void
resync(long nowMicros)
UpdatesstoredPermits
andnextFreeTicketMicros
based on the current time.(package private) 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.-
Methods inherited from class com.google.common.util.concurrent.RateLimiter
acquire, acquire, create, create, create, create, getRate, reserve, reserveAndGetWaitLength, setRate, toString, tryAcquire, tryAcquire, tryAcquire, tryAcquire
-
-
-
-
Field Detail
-
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 Detail
-
SmoothRateLimiter
private SmoothRateLimiter(RateLimiter.SleepingStopwatch stopwatch)
-
-
Method Detail
-
doSetRate
final void doSetRate(double permitsPerSecond, long nowMicros)
- Specified by:
doSetRate
in classRateLimiter
-
doSetRate
abstract void doSetRate(double permitsPerSecond, double stableIntervalMicros)
-
doGetRate
final double doGetRate()
- Specified by:
doGetRate
in classRateLimiter
-
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 classRateLimiter
- 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 classRateLimiter
- 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)
UpdatesstoredPermits
andnextFreeTicketMicros
based on the current time.
-
-