Crates.io | simple-rate-limiter |
lib.rs | simple-rate-limiter |
version | 1.0.0 |
source | src |
created_at | 2022-07-12 13:43:32.655875 |
updated_at | 2022-07-12 13:43:32.655875 |
description | A simple rate limiter that minimizes contention caused by overactive clients |
homepage | |
repository | |
max_upload_size | |
id | 624369 |
size | 11,701 |
A simple rate limiter that minimizes contention caused by overactive clients.
This rate limiter is designed with the following goals:
Limited potential for a maliciously overactive client to degrade the ability to serve others
Minimal synchronization cost between CPU caches, while also being fairly accurate for smoothing out bursts of traffic
Memory overhead linear in the amount of active keys
pub struct RateLimiter<K: Eq + Hash>;
impl<K: Eq + Hash> RateLimiter<K> {
pub fn new(limit: usize, slots: usize) -> Arc<Self>;
pub fn rotate_slots(&self);
pub fn check_limited(&self, key: K) -> bool;
}
Machine details: AMD® Ryzen 5 3600, x86_64-pc-linux-gnu, SMT enabled