Class SmoothRateLimiter
java.lang.Object
com.google.common.util.concurrent.RateLimiter
com.google.common.util.concurrent.SmoothRateLimiter
- Direct Known Subclasses:
SmoothRateLimiter.SmoothBursty
,SmoothRateLimiter.SmoothWarmingUp
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
This implements a "bursty" RateLimiter, where storedPermits are translated to zero throttling.(package private) static final class
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
FieldsModifier and TypeFieldDescription(package private) double
The maximum number of stored permits.private long
The time when the next request (no matter its size) will be granted.(package private) double
The interval between two unit requests, at our stable rate.(package private) double
The currently stored permits. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) abstract double
Returns the number of microseconds during cool down that we have to wait to get a new permit.(package private) final double
(package private) abstract void
doSetRate
(double permitsPerSecond, double stableIntervalMicros) (package private) final void
doSetRate
(double permitsPerSecond, long nowMicros) (package private) final long
queryEarliestAvailable
(long nowMicros) Returns the earliest time that permits are available (with one caveat).(package private) final 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, create, getRate, reserve, reserveAndGetWaitLength, setRate, toString, tryAcquire, tryAcquire, tryAcquire, tryAcquire, tryAcquire, tryAcquire
-
Field Details
-
storedPermits
double storedPermitsThe currently stored permits. -
maxPermits
double maxPermitsThe maximum number of stored permits. -
stableIntervalMicros
double stableIntervalMicrosThe 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 nextFreeTicketMicrosThe 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
-
SmoothRateLimiter
-
-
Method Details
-
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.
-