rate limiter - system design
1 問題
Whenever you expose a web service / api endpoint, you need to implement a rate limiter to prevent abuse of the service (DOS attacks).
Implement a RateLimiter Class with an isAllow method. Every request comes in with a unique clientID, deny a request if that client has made more than 100 requests in the past second.
這是一個流控問題。
2 輸入
Request:
client ID和時間戳timestamp
3 輸出
true or false
4 思路
保存每個client ID過去1s的所有請求。
數據結構?
?
5 關于guava的RateLimiter
5.1 RateLimiter在下列應用場景中的應用
https://www.cnblogs.com/yeyinfu/p/7316972.html
5.2 RateLimiter用在接口中不會超時嗎?
比如限制訪問數據庫,每秒不超過10,使用RateLimiter的本質是每個請求等待0.1秒。這不會導致請求超時嗎?
5.3 搶購場景降級 tryAcquire()
?
6 限流算法:令牌桶算法和漏桶算法
?
?
?
?
?
?
?
?
?
?
?
?
轉載于:https://www.cnblogs.com/hustdc/p/10950253.html
總結
以上是生活随笔為你收集整理的rate limiter - system design的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OkHttp实现登录注册验证
- 下一篇: 结合zxing 和zbar 扫一扫