abstract class SmoothRateLimiter extends RateLimiter
Modifier and Type | Class and 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.
|
RateLimiter.SleepingStopwatch
Modifier and Type | Field and 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.
|
Modifier | Constructor and Description |
---|---|
private |
SmoothRateLimiter(RateLimiter.SleepingStopwatch stopwatch) |
Modifier and Type | Method and 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)
Updates
storedPermits and nextFreeTicketMicros 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.
|
acquire, acquire, create, create, create, create, create, getRate, reserve, reserveAndGetWaitLength, setRate, toString, tryAcquire, tryAcquire, tryAcquire, tryAcquire, tryAcquire, tryAcquire
double storedPermits
double maxPermits
double stableIntervalMicros
private long nextFreeTicketMicros
private SmoothRateLimiter(RateLimiter.SleepingStopwatch stopwatch)
final void doSetRate(double permitsPerSecond, long nowMicros)
doSetRate
in class RateLimiter
abstract void doSetRate(double permitsPerSecond, double stableIntervalMicros)
final double doGetRate()
doGetRate
in class RateLimiter
final long queryEarliestAvailable(long nowMicros)
RateLimiter
queryEarliestAvailable
in class RateLimiter
final long reserveEarliestAvailable(int requiredPermits, long nowMicros)
RateLimiter
reserveEarliestAvailable
in class RateLimiter
abstract long storedPermitsToWaitTime(double storedPermits, double permitsToTake)
This always holds: 0 <= permitsToTake <= storedPermits
abstract double coolDownIntervalMicros()
void resync(long nowMicros)
storedPermits
and nextFreeTicketMicros
based on the current time.