WarmUpController预热限流算法中的疑问
- Dominant language
- Java
- Stars
- 23.1k
- Forks
- 8.1k
- PR merge metrics
- No merged PRs in 30d
Description
Guava中的预热算法:

WarmUpController的`coolDownTokens`方法:
```java
private long coolDownTokens(long currentTime, long passQps) {
// 原来的令牌数
long oldValue = storedTokens.get();
long newValue = oldValue;
// 令牌桶中的令牌数小于警戒值,说明令牌消耗速率较快
// 按照每秒count个的速率(stableInterval)放令牌
if (oldValue < warningToken) {
// 计算新的令牌数量
// 原来令牌数量 + 时间差 * 速率
newValue = (long)(oldValue + (currentTime - lastFilledTime.get()) * count / 1000);
// 当前令牌数大于警戒值,说明令牌消耗速率较慢
} else if (oldValue > warningToken) {
// 如果上一秒的QPS小于阈值的1/3
// 这个判断没看懂
if (passQps < (int)count / coldFactor) {
// 同样计算新的令牌数量
newValue = (long)(oldValue + (currentTime - lastFilledTime.get()) * count / 1000);
}
}
// 返回新令牌的数量(不能超过最大令牌数)
return Math.min(newValue, maxToken);
}
```
按照原始Guava中的算法,如果桶中的令牌数(oldValue)大于警戒值(warningToken),应当放缓加入令牌的速度,速率应该这样算:
```tex
1.0 / ((oldValue - warningToken) * slope + 1.0 / count)
```
源码中的算法为什么当前之前的QPS小于阈值的1/3时,按照最快的速率放入令牌呢?
Contributor guide
Research direction
Start by reading WarmUpController.coolDownTokens and the surrounding token-refill logic, then compare it with the Guava warm-up algorithm referenced in the issue. Done means documenting why the low-QPS branch uses the fastest refill rate, or identifying a concrete discrepancy that needs a code change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100