日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

rate limiter - system design

發(fā)布時(shí)間:2024/1/17 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 rate limiter - system design 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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.

這是一個(gè)流控問題。

2 輸入

Request:

client ID和時(shí)間戳timestamp

3 輸出

true or false

4 思路

保存每個(gè)client ID過去1s的所有請求。

數(shù)據(jù)結(jié)構(gòu)?

?

5 關(guān)于guava的RateLimiter

5.1 RateLimiter在下列應(yīng)用場景中的應(yīng)用

https://www.cnblogs.com/yeyinfu/p/7316972.html

5.2 RateLimiter用在接口中不會超時(shí)嗎?

比如限制訪問數(shù)據(jù)庫,每秒不超過10,使用RateLimiter的本質(zhì)是每個(gè)請求等待0.1秒。這不會導(dǎo)致請求超時(shí)嗎?

5.3 搶購場景降級 tryAcquire()

?

6 限流算法:令牌桶算法和漏桶算法

?

?

?

?

?

?

?

?

?

?

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/hustdc/p/10950253.html

總結(jié)

以上是生活随笔為你收集整理的rate limiter - system design的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。