pub struct ConcurrentRateLimiter { /* private fields */ }Expand description
A concurrent rate limiter that enforces a global rate limit across multiple concurrent streams. Uses a semaphore for concurrency control and an atomic timestamp to ensure min_interval between ANY two requests globally. Lock-free: uses AtomicU64 CAS loop instead of a mutex for the timestamp.
Implementations§
Source§impl ConcurrentRateLimiter
impl ConcurrentRateLimiter
Sourcepub fn new(requests_per_second: u32, max_concurrent: usize) -> Self
pub fn new(requests_per_second: u32, max_concurrent: usize) -> Self
Create a new concurrent rate limiter.
§Arguments
requests_per_second- Target requests per second rate limitmax_concurrent- Maximum concurrent requests allowed
Sourcepub async fn acquire(&self) -> OwnedSemaphorePermit
pub async fn acquire(&self) -> OwnedSemaphorePermit
Acquire a rate limit permit. Waits for both:
- A semaphore permit (concurrency limit)
- The global rate limit interval since last request
Auto Trait Implementations§
impl !Freeze for ConcurrentRateLimiter
impl RefUnwindSafe for ConcurrentRateLimiter
impl Send for ConcurrentRateLimiter
impl Sync for ConcurrentRateLimiter
impl Unpin for ConcurrentRateLimiter
impl UnsafeUnpin for ConcurrentRateLimiter
impl UnwindSafe for ConcurrentRateLimiter
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