-
Notifications
You must be signed in to change notification settings - Fork 24
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
限流算法实现解读 #209
Labels
Comments
漏桶算法和令牌桶算法,区别到底在哪里?
|
openresty 漏桶算法验证
结果QPS设在200时,未触发限流(5xx) |
This was referenced May 27, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
限流算法解读
漏桶算法
漏桶(Leaky Bucket)算法,水(请求)先进入到漏桶里,漏桶以一定的速度出水(接口有响应速率),当流入速度过大时,会直接溢出(访问频率超过接口响应速率),然后就拒绝请求,而当入小于出的情况下,漏桶不起任何作用。可以看出漏桶算法能强行限制数据的传输速率。示意图如下:
注意:在实际应用中,漏桶算法强制限定流量速率后,多出的(溢出的 excess)流量可以被利用起来,并非完全丢弃,我们可以把它收集到一个队列(burst) 里面,做流量队列,尽量做到合理利用所有资源。
漏桶算法:水(请求)先进入到漏桶里,漏桶以一定的速度出水,当水流入速度过大会直接溢出(拒绝服务),可以看出漏桶算法能强行限制数据的传输速率
用白话具体说明:假设漏斗总支持并发100个最大请求,如果超过100个请求,那么会提示系统繁忙,请稍后再试,数据输出那可以设置1个线程池,处理线程数5个,每秒处理20个请求。
openresty/lua-resty-limit-traffic源码解读
参考文章
The text was updated successfully, but these errors were encountered: