Skip to content

A Rust implementation of Sliding Window Algorithm for distributed rate limiting.

Notifications You must be signed in to change notification settings

TheDhejavu/ratelimiter-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ratelimiter-rs

A Rust implementation of Sliding Window Algorithm for distributed rate limiting.

⚠️ this is an experiment

sliding window

Installation

Add ratelimiter-rs to the [dependencies] section of your Cargo.toml:

...

[dependencies]
ratelimiter-rs = { git =  "https://github.com/TheDhejavu/ratelimiter-rs.git" }

...

Usage

src/main.rs:

use ratelimiter_rs::RateLimiter;
use std::{thread, time::Duration};

fn main() {
    let mut limiter = RateLimiter::with_in_memory();
    limiter.add_config("type1", 2, 15000).add_config("type2", 10, 30000);

    let user_id = "user12345";
    for _ in 0..10 {
        println!("RequestType1 Allowed: {}", limiter.allowed(user_id, "type1").unwrap());
        thread::sleep(Duration::from_millis(5000));
        println!("RequestType2 Allowed: {}", limiter.allowed(user_id, "type2").unwrap());
    }
}

References

About

A Rust implementation of Sliding Window Algorithm for distributed rate limiting.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages