#[repr(align(64))]pub struct RateMeter { /* private fields */ }
Expand description
Ultra-fast rate meter with sliding window calculations
Tracks events per second/minute/hour with minimal overhead. Cache-line aligned to prevent false sharing.
Implementations§
Source§impl RateMeter
impl RateMeter
Sourcepub fn with_window(window: Duration) -> Self
pub fn with_window(window: Duration) -> Self
Create rate meter with custom window size
Sourcepub fn tick(&self)
pub fn tick(&self)
Record an event - THE FASTEST PATH
This is optimized for maximum speed:
- Single atomic increment for total
- Lazy window updates only when needed
- Branch prediction friendly
Sourcepub fn rate_per_second(&self) -> f64
pub fn rate_per_second(&self) -> f64
Get rate per second
Sourcepub fn rate_per_minute(&self) -> f64
pub fn rate_per_minute(&self) -> f64
Get rate per minute
Sourcepub fn rate_per_hour(&self) -> f64
pub fn rate_per_hour(&self) -> f64
Get rate per hour
Sourcepub fn exceeds_rate(&self, limit: f64) -> bool
pub fn exceeds_rate(&self, limit: f64) -> bool
Check if rate exceeds limit
Sourcepub fn can_allow(&self, n: u32, limit: f64) -> bool
pub fn can_allow(&self, n: u32, limit: f64) -> bool
Check if we can allow N more events without exceeding limit
Sourcepub fn tick_if_under_limit(&self, limit: f64) -> bool
pub fn tick_if_under_limit(&self, limit: f64) -> bool
Rate limiting - tick only if under limit
Sourcepub fn tick_burst_if_under_limit(&self, n: u32, limit: f64) -> bool
pub fn tick_burst_if_under_limit(&self, n: u32, limit: f64) -> bool
Burst rate limiting - allow N events if under limit
Trait Implementations§
impl Send for RateMeter
impl Sync for RateMeter
Auto Trait Implementations§
impl !Freeze for RateMeter
impl RefUnwindSafe for RateMeter
impl Unpin for RateMeter
impl UnwindSafe for RateMeter
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