#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 3/week @ 2024-08-19 21/week @ 2024-09-02 42/week @ 2024-09-16 44/week @ 2024-09-23 8/week @ 2024-09-30 61/week @ 2024-10-07 5/week @ 2024-10-14 33/week @ 2024-10-21 25/week @ 2024-10-28 8/week @ 2024-11-04 49/week @ 2024-11-11 6/week @ 2024-11-18 1/week @ 2024-11-25 19/week @ 2024-12-02

76 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