V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
RedisMasterNode

uber-go 中的 ratelimit 包, 为何 sleepFor 不能小于 maxSlack 呢?

  •  
  •   RedisMasterNode · Jan 24, 2021 · 1354 views
    This topic created in 1928 days ago, the information mentioned may be changed or developed.

    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.
    ...
    

    萌新提问, 感谢~

    2 replies    2021-01-28 11:45:03 +08:00
    zhangsanfeng2012
        1
    zhangsanfeng2012  
       Jan 25, 2021
    限制突发吧,我猜的
    RedisMasterNode
        2
    RedisMasterNode  
    OP
       Jan 28, 2021
    @zhangsanfeng2012 道理都懂,可是代码里面明明没有在用
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1017 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 22:37 · PVG 06:37 · LAX 15:37 · JFK 18:37
    ♥ Do have faith in what you're doing.