Crates.io | ratelimiter-rs |
lib.rs | ratelimiter-rs |
version | 0.1.5 |
source | src |
created_at | 2023-04-14 12:04:49.705452 |
updated_at | 2023-12-17 16:32:07.968015 |
description | a lite ratelimit utils for rust |
homepage | |
repository | https://github.com/heqingpan/ratelimiter-rs |
max_upload_size | |
id | 839114 |
size | 12,836 |
A lite ratelimit utils for rust.
use std::thread;
use std::time::Duration;
use ratelimiter_rs::{QpsLimiter,RateLimiter,AtomicRateLimiter,now_millis};
fn qpslimiter(){
let mut limiter = QpsLimiter::new(10);
// AtomicRateLimiter can clone to other thread and use
//let limiter = AtomicRateLimiter::new(10);
let mut times = 0;
for _ in 0..3000 {
thread::sleep(Duration::from_millis(1));
if limiter.acquire() {
times +=1;
//println!("time: {}",now_millis())
}
else{
continue;
}
}
println!("time: {}, times: {}",now_millis(),×);
}