Skip to content

killer4639/rust-rate-limiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Rate Limiter

A gRPC-based rate limiter service built with Rust, Tonic, and Tokio.

Building

cargo build

Running

cargo run

The server will start listening on 127.0.0.1:50051 (IPv4 localhost on port 50051).

Testing with grpcurl

# Install grpcurl if not already installed
# https://github.com/fullstorydev/grpcurl/releases

# Send a ping request (reflection enabled, no .proto needed)
grpcurl -plaintext -d '{"message":"hello"}' 127.0.0.1:50051 rate_limiter.RateLimiter/Ping

Example Clients and Load Tests

The examples/ directory contains several binaries for testing and benchmarking:

  • client.rs: Simple gRPC client for manual requests.
  • load_test.rs: Multi-threaded, configurable load test for rate limiter and heartbeat endpoints.
  • loop_load_test.rs: Repeated requests in a loop (single-threaded).
  • single_threaded_load_test.rs: Basic single-threaded load test for baseline throughput.

Running the Server

cargo run

Running the Example Client

cargo run --example client

Running the Main Load Test

Always run load tests with the --release flag to avoid debug-mode overhead.

# Run rate limiter endpoint load test
cargo run --release --example load_test -- rate

# Run heartbeat endpoint load test
cargo run --release --example load_test -- heartbeat

# Run both endpoints
cargo run --release --example load_test -- both

Running Other Load Test Variants

cargo run --release --example loop_load_test
cargo run --release --example single_threaded_load_test

Load Test Results

Metric Value
Throughput (req/s) 300,000
Mode release
Test both endpoints

Project Structure

  • proto/ - Protocol Buffer definitions
  • src/ - Rust source code
  • build.rs - Build script to compile proto files
  • examples/ - Example client binaries (run via cargo run --example client)

About

Rate limiter in Rust for fast performance

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages