Take
方法见: https://github.com/uber-go/ratelimit/blob/master/limiter_atomic.go
其中有一段代码:
...
if newState.sleepFor < t.maxSlack {
newState.sleepFor = t.maxSlack
}
...
sleepFor
是“间隔时间-上次执行时间至当前时间”, 例如间隔时间为 1 秒, 上次执行时间为 5 秒前, sleepFor 就是-4
sleepFor
在末尾用于t.clock.Sleep(newState.sleepFor)
,貌似没有别的用途,那为什么需要让它不能小于t.maxSlack
?
或者如果有 dalao 明白这段注释的意思也可以解释一下:
...
// We shouldn't allow sleepFor to get too negative, since it would mean that
// a service that slowed down a lot for a short period of time would get
// a much higher RPS following that.
...
萌新提问, 感谢~
1
zhangsanfeng2012 2021-01-25 09:40:57 +08:00
限制突发吧,我猜的
|
2
RedisMasterNode OP @zhangsanfeng2012 道理都懂,可是代码里面明明没有在用
|