static final class SmoothRateLimiter.SmoothWarmingUp extends SmoothRateLimiter
^ throttling | cold + / interval | /. | / . | / . ← "warmup period" is the area of the trapezoid between | / . thresholdPermits and maxPermits | / . | / . | / . stable +----------/ WARM . interval | . UP . | . PERIOD. | . . 0 +----------+-------+--------------→ storedPermits 0 thresholdPermits maxPermitsBefore going into the details of this particular function, let's keep in mind the basics:
In summary, the time it takes to move to the left (spend K permits), is equal to the area of the function of width == K.
Assuming we have saturated demand, the time to go from maxPermits to thresholdPermits is equal to warmupPeriod. And the time to go from thresholdPermits to 0 is warmupPeriod/2. (The reason that this is warmupPeriod/2 is to maintain the behavior of the original implementation where coldFactor was hard coded as 3.)
It remains to calculate thresholdsPermits and maxPermits.
thresholdPermits = 0.5 * warmupPeriod / stableInterval
maxPermits = thresholdPermits + 2 * warmupPeriod / (stableInterval + coldInterval)
SmoothRateLimiter.SmoothBursty, SmoothRateLimiter.SmoothWarmingUp
RateLimiter.SleepingStopwatch
Modifier and Type | Field and Description |
---|---|
private double |
coldFactor |
private double |
slope
The slope of the line from the stable interval (when permits == 0), to the cold interval
(when permits == maxPermits)
|
private double |
thresholdPermits |
private long |
warmupPeriodMicros |
maxPermits, stableIntervalMicros, storedPermits
Constructor and Description |
---|
SmoothWarmingUp(RateLimiter.SleepingStopwatch stopwatch,
long warmupPeriod,
java.util.concurrent.TimeUnit timeUnit,
double coldFactor) |
Modifier and Type | Method and Description |
---|---|
(package private) double |
coolDownIntervalMicros()
Returns the number of microseconds during cool down that we have to wait to get a new permit.
|
(package private) void |
doSetRate(double permitsPerSecond,
double stableIntervalMicros) |
private double |
permitsToTime(double permits) |
(package private) 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.
|
doGetRate, doSetRate, queryEarliestAvailable, reserveEarliestAvailable, resync
acquire, acquire, create, create, create, create, create, getRate, reserve, reserveAndGetWaitLength, setRate, toString, tryAcquire, tryAcquire, tryAcquire, tryAcquire, tryAcquire, tryAcquire
private final long warmupPeriodMicros
private double slope
private double thresholdPermits
private double coldFactor
SmoothWarmingUp(RateLimiter.SleepingStopwatch stopwatch, long warmupPeriod, java.util.concurrent.TimeUnit timeUnit, double coldFactor)
void doSetRate(double permitsPerSecond, double stableIntervalMicros)
doSetRate
in class SmoothRateLimiter
long storedPermitsToWaitTime(double storedPermits, double permitsToTake)
SmoothRateLimiter
This always holds: 0 <= permitsToTake <= storedPermits
storedPermitsToWaitTime
in class SmoothRateLimiter
private double permitsToTime(double permits)
double coolDownIntervalMicros()
SmoothRateLimiter
coolDownIntervalMicros
in class SmoothRateLimiter