Crates.io | prob-rate-limiter |
lib.rs | prob-rate-limiter |
version | 0.1.1 |
source | src |
created_at | 2022-04-26 03:47:28.600213 |
updated_at | 2022-04-26 04:27:41.958806 |
description | Proababilistic rate limiter. Smoothly shed load to prevent overload. |
homepage | |
repository | https://gitlab.com/leonhard-llc/ops |
max_upload_size | |
id | 574392 |
size | 20,515 |
ProbRateLimiter
is a probabilistic rate limiter.
When load approaches the configured limit,
the struct chooses randomly whether to accept or reject each request.
It adjusts the probability of rejection so throughput is steady around the limit.
unsafe
or unsafe depsunsafe
or depsunsafe
parking_lot
try_acquire
.let mut limiter = ProbRateLimiter::new(10.0).unwrap();
let mut now = Instant::now();
assert!(limiter.check(5, now));
assert!(limiter.check(5, now));
now += Duration::from_secs(1);
assert!(limiter.check(5, now));
assert!(limiter.check(5, now));
now += Duration::from_secs(1);
assert!(limiter.check(5, now));
assert!(limiter.check(5, now));
now += Duration::from_secs(1);
assert!(limiter.check(5, now));
assert!(limiter.check(5, now));
now += Duration::from_secs(1);
assert!(limiter.check(5, now));
assert!(limiter.check(5, now));
assert!(!limiter.check(5, now));
Metric output format: x/y
x = unsafe code used by the build
y = total unsafe code found in the crate
Symbols:
🔒 = No `unsafe` usage found, declares #![forbid(unsafe_code)]
❓ = No `unsafe` usage found, missing #![forbid(unsafe_code)]
☢️ = `unsafe` usage found
Functions Expressions Impls Traits Methods Dependency
0/0 0/0 0/0 0/0 0/0 🔒 prob-rate-limiter 0.1.1
0/0 0/0 0/0 0/0 0/0 🔒 └── oorandom 11.1.3
0/0 0/0 0/0 0/0 0/0
new
. Add more docs.License: Apache-2.0