mirror of
https://github.com/cloudflare/pingora.git
synced 2024-09-20 02:31:35 +02:00
Update ratelimiter.md
update rate_limiter_map initialize code
This commit is contained in:
parent
bffc9f4f23
commit
80231711f9
1 changed files with 2 additions and 11 deletions
|
@ -98,16 +98,7 @@ impl ProxyHttp for LB {
|
|||
// retrieve the current window requests
|
||||
let curr_window_requests = {
|
||||
let mut rate_limiter_map = RATE_LIMITER_MAP.lock().unwrap();
|
||||
let rate_limiter = match rate_limiter_map.get(&appid) {
|
||||
None => {
|
||||
let limiter = Rate::new(Duration::from_secs(1));
|
||||
rate_limiter_map.insert(appid.clone(), limiter);
|
||||
rate_limiter_map.get(&appid).unwrap()
|
||||
}
|
||||
Some(limiter) => {
|
||||
limiter
|
||||
}
|
||||
};
|
||||
let rate_limiter = rate_limiter_map.entry(appid.clone()).insert_or_with(|| Rate::new(Duration::from_secs(1)));
|
||||
rate_limiter.observe(&appid, 1)
|
||||
};
|
||||
if curr_window_requests > MAX_REQ_PER_SEC { // rate limited, return 429
|
||||
|
@ -122,4 +113,4 @@ impl ProxyHttp for LB {
|
|||
Ok(false)
|
||||
}
|
||||
}
|
||||
```
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue