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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classSmoothRateLimiter.SmoothBurstyThis implements a "bursty" RateLimiter, where storedPermits are translated to zero throttling.(package private) static classSmoothRateLimiter.SmoothWarmingUpThis 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) doublemaxPermitsThe maximum number of stored permits.private longnextFreeTicketMicrosThe time when the next request (no matter its size) will be granted.(package private) doublestableIntervalMicrosThe interval between two unit requests, at our stable rate.(package private) doublestoredPermitsThe currently stored permits.
-
Constructor Summary
Constructors Modifier Constructor Description privateSmoothRateLimiter(RateLimiter.SleepingStopwatch stopwatch)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) abstract doublecoolDownIntervalMicros()Returns the number of microseconds during cool down that we have to wait to get a new permit.(package private) doubledoGetRate()(package private) abstract voiddoSetRate(double permitsPerSecond, double stableIntervalMicros)(package private) voiddoSetRate(double permitsPerSecond, long nowMicros)(package private) longqueryEarliestAvailable(long nowMicros)Returns the earliest time that permits are available (with one caveat).(package private) longreserveEarliestAvailable(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) voidresync(long nowMicros)UpdatesstoredPermitsandnextFreeTicketMicrosbased on the current time.(package private) abstract longstoredPermitsToWaitTime(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, create, getRate, reserve, reserveAndGetWaitLength, setRate, toString, tryAcquire, tryAcquire, 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:
doSetRatein classRateLimiter
-
doSetRate
abstract void doSetRate(double permitsPerSecond, double stableIntervalMicros)
-
doGetRate
final double doGetRate()
- Specified by:
doGetRatein classRateLimiter
-
queryEarliestAvailable
final long queryEarliestAvailable(long nowMicros)
Description copied from class:RateLimiterReturns the earliest time that permits are available (with one caveat).- Specified by:
queryEarliestAvailablein 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:RateLimiterReserves the requested number of permits and returns the time that those permits can be used (with one caveat).- Specified by:
reserveEarliestAvailablein 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)
UpdatesstoredPermitsandnextFreeTicketMicrosbased on the current time.
-
-