-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
流控规则-匀速排队控制效果统计不够准确 | Throttling (rate limiter controlBehavior) not accurate enough #399
Comments
感谢反馈,这里有一个相似的 issue: #259 现在主要的问题是 另外改成 nano 以后,取时间就要用 Hi, thanks for reporting. A related issue here: #259
|
@sczyh30 给了一个新的解决方案,可以试试。 |
@sczyh30 System.nanoTime性能不好应该是一个可以忽略的问题,在这种允许排队的场景下,这个性能损耗,与统计不准确相比的权衡,个人倾向于让限流更加精准,而不是这个并发的性能。 |
就这个问题我也分享下我的观点,仅针对这个精度“有问题”的流量整形算法:
鉴于此,基于匀速器的实现目的,即将突发流量均匀分布到单位时间内(一般来说是1秒),简化为 |
@jasonjoo2010 理论上认可你的较粗粒度的观点,但实际使用中,差异很大,设置300qps时,原计算模型能够计算到334,多线程的时候会计算到更高的qps,这种情况下,后端服务是不可接受的,误差放大太厉害了。 |
柳, 可能你没完全理解我的意思,简单来说,就是算精睡粗保跨界。 算精,拿纳秒、皮秒来计算没任何问题; |
看到这个解释,比较理解了,谢谢指教~ |
RateLimiterController
在RateLimiterController中,计算costTime的时候,使用的是毫秒统计,就会出现
long cost = Math.round(1 * 1 / 160 * 1000) = Math.round(1 * 1 / 170 * 1000) = 6 ms
的情况,也就是设置阈值为160和170得到的效果是一样的,都是会将qps限制在167.误差评估:diff(100 / int(1000/n), n)
以下是我在原版的PaceController的修改,修改为纳秒时间, like this:
测试代码:
先这样吧~~~
The text was updated successfully, but these errors were encountered: