pub struct FixedWindowRateLimiter { /* private fields */ }Expand description
固定窗口限流器
将时间划分为固定大小的窗口,每个 key 在每个窗口内有独立的计数器。
当计数器超过 max_requests 时拒绝请求。
§边界突刺
固定窗口算法存在边界突刺问题:如果窗口结束前 1 秒通过了 max_requests
个请求,新窗口开始后第 1 秒又通过了 max_requests 个请求,则 2 秒内
通过了 2 * max_requests 个请求。如需更平滑的限流,请使用
SlidingWindowRateLimiter 或 TokenBucketRateLimiter。
Implementations§
Trait Implementations§
Source§impl RateLimiter for FixedWindowRateLimiter
impl RateLimiter for FixedWindowRateLimiter
fn acquire(&self, key: &str) -> Result<RateLimitResult, RateLimitError>
fn try_acquire(&self, key: &str) -> Result<RateLimitResult, RateLimitError>
fn reset(&self, key: &str) -> Result<(), RateLimitError>
Auto Trait Implementations§
impl Freeze for FixedWindowRateLimiter
impl RefUnwindSafe for FixedWindowRateLimiter
impl Send for FixedWindowRateLimiter
impl Sync for FixedWindowRateLimiter
impl Unpin for FixedWindowRateLimiter
impl UnsafeUnpin for FixedWindowRateLimiter
impl UnwindSafe for FixedWindowRateLimiter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more