#rate-limiting #qps

ratelimiter-rs

a lite ratelimit utils for rust

6 releases

0.1.5 Dec 17, 2023
0.1.4 Dec 17, 2023
0.1.3 Apr 17, 2023

#1 in #ratelimit

Download history 40/week @ 2024-06-10 24/week @ 2024-06-17 14/week @ 2024-06-24 10/week @ 2024-07-01 25/week @ 2024-07-08 13/week @ 2024-07-15 17/week @ 2024-07-29 41/week @ 2024-08-05 5/week @ 2024-08-12 3/week @ 2024-08-19 21/week @ 2024-09-02 42/week @ 2024-09-16 44/week @ 2024-09-23

107 downloads per month
Used in rnacos

MIT/Apache

11KB
277 lines

ratelimiter-rs

A lite ratelimit utils for rust.

examples

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(),&times);
}

No runtime deps