limiteron

Crates.iolimiteron
lib.rslimiteron
version0.1.1
created_at2026-01-19 09:15:06.962554+00
updated_at2026-01-19 09:21:38.811469+00
descriptionUnified flow control framework for Rust
homepage
repositoryhttps://github.com/Kirky-X/limiteron
max_upload_size
id2054062
size1,436,831
Kirky (Kirky-X)

documentation

README

Limiteron Logo

Version Rust Version License Build GitHub Stars GitHub Forks GitHub Issues License

Rust Unified Flow Control Framework

Features โ€ข Quick Start โ€ข Documentation โ€ข Examples โ€ข Contributing


๐Ÿ“‹ Table of Contents

Click to expand

โœจ Features

๐ŸŽฏ Core Features

  • โœ… Multiple Rate Limiting Algorithms - Token bucket, fixed window, sliding window, concurrency control
  • โœ… Ban Management - IP ban, automatic ban, ban priority
  • โœ… Quota Control - Quota allocation, quota alerts, quota overdraw
  • โœ… Circuit Breaker - Automatic failover, state recovery, fallback strategy

โšก Advanced Features

  • ๐Ÿš€ High Performance - Latency < 200ฮผs P99
  • ๐Ÿ” Secure and Reliable - Memory safety, SQL injection protection
  • ๐ŸŒ Multi-Storage Support - PostgreSQL, Redis, in-memory storage
  • ๐Ÿ“ฆ Easy to Use - Macro support, clean API

๐ŸŽจ ็‰นๆ€งไบฎ็‚น

graph LR
    A[่ฏทๆฑ‚] --> B[ๆ ‡่ฏ†็ฌฆๆๅ–]
    B --> C[้™ๆตๆฃ€ๆŸฅ]
    B --> D[ๅฐ็ฆๆฃ€ๆŸฅ]
    B --> E[้…้ขๆฃ€ๆŸฅ]
    C --> F[ๅ†ณ็ญ–้“พ]
    D --> F
    E --> F
    F --> G[ๅ…่ฎธ/ๆ‹’็ป]

    style A fill:#e1f5ff
    style B fill:#b3e5fc
    style C fill:#81d4fa
    style D fill:#81d4fa
    style E fill:#81d4fa
    style F fill:#4fc3f7
    style G fill:#29b6f6

๐ŸŽฏ Use Cases

๐Ÿ’ผ Enterprise Applications
use limiteron::limiters::{Limiter, TokenBucketLimiter};

async fn enterprise_api() -> Result<(), Box<dyn std::error::Error>> {
    let limiter = TokenBucketLimiter::new(100, 10); // 100 tokens, refill 10 per second

    // Rate limiting check
    match limiter.allow(1).await {
        Ok(true) => {
            // Process request
            process_request().await;
        }
        Ok(false) => {
            eprintln!("Rate limit exceeded");
        }
        Err(e) => {
            eprintln!("Error: {:?}", e);
        }
    }

    Ok(())
}

async fn process_request() {
    println!("Processing request...");
}

Suitable for enterprise applications requiring high concurrency and reliability.

๐Ÿ”ง API Services
use limiteron::flow_control;

#[flow_control(rate = "100/s", quota = "10000/m", concurrency = 50)]
async fn api_handler(user_id: &str) -> Result<String, limiteron::error::FlowGuardError> {
    // API business logic
    Ok("Success".to_string())
}

Suitable for protecting API services from abuse and DDoS attacks.

๐ŸŒ Web Applications
use limiteron::ban_manager::{BanManager, BanTarget};
use limiteron::storage::MockBanStorage;
use std::sync::Arc;

async fn web_app() -> Result<(), Box<dyn std::error::Error>> {
    // Create storage and ban manager
    let storage = Arc::new(MockBanStorage::default());
    let ban_manager = BanManager::new(storage, None).await?;

    // Check if user is banned
    let user_target = BanTarget::UserId("user123".to_string());
    if let Some(ban_record) = ban_manager.is_banned(&user_target).await? {
        println!("User is banned: {:?}", ban_record);
        return Err("User is banned".into());
    }

    // Process request
    println!("Processing request for user123");
    Ok(())
}

Suitable for web applications that need to prevent malicious users and crawlers.


๐Ÿš€ Quick Start

Installation

๐Ÿฆ€ Cargo

[dependencies]
limiteron = { version = "0.1", features = ["macros"] }

๐Ÿ”ง Features

[dependencies]
limiteron = { version = "0.1", features = ["postgres", "redis", "macros"] }

Feature Flags

๐ŸŽ›๏ธ ๅฏ้€‰็‰นๆ€ง้…็ฝฎ

Limiteron ไฝฟ็”จ feature flags ๆฅๆŽงๅˆถๅŠŸ่ƒฝๅฏ็”จ๏ผŒ้ป˜่ฎคๅชๅฏ็”จๅ†…ๅญ˜ๅญ˜ๅ‚จ๏ผš

้ข„ๅฎšไน‰็ป„ๅˆ

# ๆœ€ๅฐๅŒ–๏ผšไป…ๆ ธๅฟƒ้™ๆต
limiteron = { version = "0.1", features = ["minimal"] }

# ๆ ‡ๅ‡†๏ผšๆ ธๅฟƒ + ๅŸบ็ก€้ซ˜็บงๅŠŸ่ƒฝ
limiteron = { version = "0.1", features = ["standard"] }

# ๅฎŒๆ•ด๏ผšๆ‰€ๆœ‰ๅŠŸ่ƒฝ
limiteron = { version = "0.1", features = ["full"] }

ๅ•็‹ฌ็‰นๆ€ง

# ๅญ˜ๅ‚จๅŽ็ซฏ
limiteron = { version = "0.1", features = ["postgres", "redis"] }

# ้ซ˜็บงๅŠŸ่ƒฝ
limiteron = { version = "0.1", features = ["ban-manager", "quota-control", "circuit-breaker"] }

# ๅฎๆ”ฏๆŒ
limiteron = { version = "0.1", features = ["macros"] }
๐Ÿ“‹ ๅฎŒๆ•ด็‰นๆ€งๅˆ—่กจ
็‰นๆ€ง ๆ่ฟฐ ้ป˜่ฎค
memory ๅ†…ๅญ˜ๅญ˜ๅ‚จ โœ…
postgres PostgreSQL ๅญ˜ๅ‚จ โŒ
redis Redis ๅญ˜ๅ‚จ โŒ
ban-manager ๅฐ็ฆ็ฎก็† โŒ
quota-control ้…้ขๆŽงๅˆถ โŒ
circuit-breaker ็†”ๆ–ญๅ™จ โŒ
macros ๅฎๆ”ฏๆŒ โŒ
telemetry ้ฅๆต‹ๅ’Œ่ฟฝ่ธช โŒ
monitoring Prometheus ๆŒ‡ๆ ‡ โŒ

Basic Usage

๐ŸŽฌ 5-Minute Quick Start

Step 1: Add Dependency

[dependencies]
limiteron = { version = "0.1", features = ["macros"] }

Step 2: Use Macro

use limiteron::flow_control;

#[flow_control(rate = "10/s")]
async fn api_call() -> Result<String, limiteron::error::FlowGuardError> {
    Ok("Success".to_string())
}
๐Ÿ“– Complete Example
use limiteron::limiters::{Limiter, TokenBucketLimiter};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Step 1: Create limiter
    let limiter = TokenBucketLimiter::new(10, 1); // 10 tokens, refill 1 per second

    // Step 2: Check rate limit
    match limiter.allow(1).await {
        Ok(true) => println!("โœ… Request allowed"),
        Ok(false) => println!("โŒ Request rate limited"),
        Err(e) => println!("โŒ Error: {:?}", e),
    }

    // Step 3: Use with cost
    match limiter.allow(2).await {
        Ok(true) => println!("โœ… Request with cost 2 allowed"),
        Ok(false) => println!("โŒ Request with cost 2 rate limited"),
        Err(e) => println!("โŒ Error: {:?}", e),
    }

    Ok(())
}

๐Ÿ“š Documentation


User Guide

Complete usage guide

API Reference

Complete API documentation

FAQ

Frequently asked questions

Examples

Code examples

๐Ÿ“– Additional Resources


๐ŸŽจ Examples

๐Ÿ’ก Practical Examples

๐Ÿ“ Example 1: Basic Rate Limiting

use limiteron::limiters::{Limiter, TokenBucketLimiter};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let limiter = TokenBucketLimiter::new(10, 1);

    for i in 0..15 {
        match limiter.allow(1).await {
            Ok(true) => println!("Request {} โœ…", i),
            Ok(false) => println!("Request {} โŒ", i),
            Err(e) => println!("Request {} Error: {:?}", i, e),
        }
    }

    Ok(())
}
View Output
Request 0 โœ…
Request 1 โœ…
...
Request 9 โœ…
Request 10 โŒ
...
Request 14 โŒ
โœ… First 10 requests allowed, remaining rate limited

๐Ÿ”ฅ Example 2: Using Macro

use limiteron::flow_control;

#[flow_control(rate = "100/s", quota = "10000/m", concurrency = 50)]
async fn api_handler(user_id: &str) -> Result<String, limiteron::error::FlowGuardError> {
    // API business logic
    Ok(format!("Processing request for user {}", user_id))
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let result = api_handler("user123").await?;
    println!("{}", result);
    Ok(())
}
View Output
Processing request for user123
โœ… Macro automatically handles rate limiting

๐Ÿ“‚ View All Examples โ†’


๐Ÿ—๏ธ Architecture

System Overview

graph TB
    A[User App] --> B[API Layer]
    B --> C[Governor]
    C --> D[Identifier Extraction]
    C --> E[Decision Chain]
    D --> F[Matchers]
    E --> G[Limiters]
    E --> H[Ban Management]
    E --> I[Quota Control]
    E --> J[Circuit Breaker]
    G --> K[L2/L3 Cache]
    H --> K
    I --> K
    K --> L[Storage Layer]
    L --> M[PostgreSQL]
    L --> N[Redis]
    L --> O[Memory]

    style A fill:#e1f5ff
    style B fill:#b3e5fc
    style C fill:#81d4fa
    style D fill:#4fc3f7
    style E fill:#4fc3f7
    style F fill:#29b6f6
    style G fill:#29b6f6
    style H fill:#29b6f6
    style I fill:#29b6f6
    style J fill:#29b6f6
    style K fill:#0288d1
    style L fill:#0277bd
    style M fill:#01579b
    style N fill:#01579b
    style O fill:#01579b
๐Ÿ“ Component Details
Component Description Status
Governor Main controller, end-to-end flow control โœ… Stable
Matchers Identifier extraction (IP, User ID, Device ID, etc.) โœ… Stable
Limiters Multiple rate limiting algorithms โœ… Stable
Ban Management IP ban, automatic ban โœ… Stable
Quota Control Quota allocation, quota alerts โœ… Stable
Circuit Breaker Automatic failover, state recovery โœ… Stable
Cache L2/L3 cache support โœ… Stable
Storage Layer PostgreSQL, Redis, in-memory โœ… Stable

โš™๏ธ Configuration

๐ŸŽ›๏ธ Configuration Options

Basic Configuration

[limiter]
rate_limit = "100/s"
quota_limit = "10000/m"
concurrency_limit = 50

[cache]
l2_capacity = 10000
l3_capacity = 100000

Advanced Configuration

[limiter]
rate_limit = "100/s"
quota_limit = "10000/m"
concurrency_limit = 50

[storage]
type = "redis"
connection_string = "redis://localhost:6379"

[telemetry]
enable_metrics = true
enable_tracing = true
๐Ÿ”ง All Configuration Options
Option Type Default Description
rate_limit String "100/s" Rate limit
quota_limit String "10000/m" Quota limit
concurrency_limit Integer 50 Concurrency limit
l2_capacity Integer 10000 L2 cache capacity
l3_capacity Integer 100000 L3 cache capacity
storage_type String "memory" Storage type
enable_metrics Boolean false Enable metrics
enable_tracing Boolean false Enable tracing

๐Ÿงช Testing

# Run all tests
cargo test --all-features

# Run specific test
cargo test test_name

# Run integration tests
cargo test --test integration_tests

# Run benchmarks
cargo bench

๐Ÿ“Š Performance

โšก Benchmark Results

Note: The following data represents actual benchmark results from comprehensive testing (2026-01-19).

Throughput

Limiter Type Actual Target Achievement
TokenBucket 12M+ ops/s 500K ops/s โœ… 24x
FixedWindow 20M+ ops/s 300K ops/s โœ… 66x
ConcurrencyLimiter 12M+ ops/s 200K ops/s โœ… 60x

Latency

Percentile TokenBucket FixedWindow
P50 < 100ns < 100ns
P95 < 200ns < 150ns
P99 < 1ยตs < 500ns

Concurrency Test Results

Test Item Result Status
Data Consistency 100% โœ… Pass
High Concurrency Stability 50/100 concurrent โœ… Pass
Rate Limit Correctness 1000/1000 โœ… Pass
๐Ÿ“ˆ Detailed Benchmarks
# Run performance tests
cd temp/comprehensive_test
./target/release/functional_test    # Functional tests
./target/release/performance_test   # Performance tests
./target/release/concurrency_test   # Concurrency tests

Sample output:

ๅŠŸ่ƒฝๆต‹่ฏ•: 7/7 Pass (100%)
TokenBucket: 12,088,759 ops/s
FixedWindow: 19,920,188 ops/s
ConcurrencyLimiter: 11,891,237 ops/s
ๅนถๅ‘ๆต‹่ฏ•: 100% ๆ•ฐๆฎไธ€่‡ดๆ€ง

๐Ÿ”’ Security

๐Ÿ›ก๏ธ Security Features


Memory Safety
Rust guarantees memory safety

Input Validation
Comprehensive input checking

SQL Injection Protection
Parameterized queries

Password Protection
Secure password storage
๐Ÿ” Security Details

Security Measures

  • โœ… Memory Protection - Rust memory safety guarantees
  • โœ… Input Validation - IP address, User ID, MAC address validation
  • โœ… SQL Injection Protection - Using parameterized queries
  • โœ… Password Protection - Using secrecy library for sensitive data
  • โœ… Audit Logging - Complete operation tracking

Reporting Security Issues

Please report security vulnerabilities through GitHub Issues.


๐Ÿ—บ๏ธ Roadmap

๐ŸŽฏ Development Plan

gantt
    title Limiteron Roadmap
    dateFormat  YYYY-MM
    section Phase 1
    Core Features           :done, 2026-01, 2026-03
    section Phase 2
    Feature Extensions      :active, 2026-03, 2026-06
    section Phase 3
    Performance Optimization :2026-06, 2026-09
    section Phase 4
    Production Ready        :2026-09, 2026-12

โœ… Completed

  • Core rate limiting
  • Ban management
  • Quota control
  • Circuit breaker
  • Unit and integration tests
  • Macro support
  • PostgreSQL and Redis storage

๐Ÿšง In Progress

  • Performance optimization
  • Monitoring and tracing improvements
  • Documentation completion
  • Example code additions

๐Ÿ“‹ Planned

  • Lua script enhancements
  • Custom matcher extensions
  • Additional storage backends
  • Web UI management interface

๐Ÿ’ก Future Ideas

  • Distributed rate limiting
  • Machine learning-driven rate limiting
  • Additional rate limiting algorithms
  • Community plugin system

๐Ÿค Contributing

๐Ÿ’– Welcome Contributions!

๐Ÿ› Report Issues

Found a bug?
Create Issue

๐Ÿ’ก Feature Requests

Have a suggestion?
Start Discussion

๐Ÿ”ง Submit Code

Want to contribute?
Fork & PR

๐Ÿ“ Contribution Guide

How to Contribute

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/yourusername/limiteron.git
  3. Create a branch: git checkout -b feature/amazing-feature
  4. Make your changes
  5. Test your changes: cargo test --all-features
  6. Commit your changes: git commit -m 'Add amazing feature'
  7. Push to branch: git push origin feature/amazing-feature
  8. Create a Pull Request

Code Style

  • Follow Rust standard coding conventions
  • Write comprehensive tests
  • Update documentation
  • Add examples for new features

๐Ÿ“„ License

This project is licensed under Apache 2.0:

License: Apache 2.0


๐Ÿ™ Acknowledgments

Built with Excellent Tools


Rust

GitHub

Open Source

Community

Special Thanks

  • ๐ŸŒŸ Dependencies - Built on these excellent projects:

  • ๐Ÿ‘ฅ Contributors - Thanks to all contributors!

  • ๐Ÿ’ฌ Community - Special thanks to community members


๐Ÿ“ž Contact & Support


Issues

Report bugs and errors

Discussions

Ask questions and share ideas

GitHub

View source code

Stay Connected

GitHub


โญ Star History

Star History Chart


๐Ÿ’ Support This Project

If you find this project useful, please consider giving it a โญ๏ธ!

Built with โค๏ธ by Kirky.X

โฌ† Back to Top


ยฉ 2026 Kirky.X. All rights reserved.

Commit count: 73

cargo fmt