| Crates.io | rat_congestion |
| lib.rs | rat_congestion |
| version | 0.1.0 |
| created_at | 2025-09-26 06:38:45.42574+00 |
| updated_at | 2025-09-26 06:38:45.42574+00 |
| description | High-performance congestion control algorithms for network protocols |
| homepage | https://github.com/0ldm0s/rat_congestion |
| repository | https://github.com/0ldm0s/rat_congestion |
| max_upload_size | |
| id | 1855483 |
| size | 171,356 |
一个高性能、平台优化的拥塞控制库,实现了 BBR 和 CUBIC 算法,具备智能切换能力。
rat_congestion 是一个专为网络协议设计的纯计算拥塞控制引擎。该库不收集任何系统数据,所有网络数据均由调用方提供,确保了最大的灵活性和性能。
在 Cargo.toml 中添加:
[dependencies]
rat_congestion = "0.1.0"
use rat_congestion::{CongestionController, NetworkMetrics, MetricsWindow};
use std::time::Duration;
// 创建带有自动平台优化的控制器
// 注意:实际使用中需要提供 NetworkMetrics 和 MetricsWindow 的实现
let mut controller = CongestionController::new(metrics, metrics_window);
// 处理数据包确认
controller.on_packet_acked(1500, Duration::from_millis(50));
// 处理数据包丢失
controller.on_packet_lost(1500);
// 获取当前窗口大小
let window_size = controller.window_size();
// 获取当前发送速率
let pacing_rate = controller.pacing_rate();
use rat_congestion::{CongestionController, ControllerConfig};
// 创建自定义配置
let config = ControllerConfig::builder()
.initial_algorithm("bbr")
.auto_switching(true)
.platform_optimized(true)
.build();
// 使用自定义配置创建控制器
let mut controller = CongestionController::with_config(config, metrics, metrics_window);
// 平台优化配置(推荐)
let config = ControllerConfig::platform_optimized();
// 高性能配置
let config = ControllerConfig::high_performance();
// 稳定网络配置
let config = ControllerConfig::stable_network();
// 自适应配置
let config = ControllerConfig::adaptive();
let config = ControllerConfig::builder()
.initial_algorithm("cubic") // 初始算法: "bbr", "cubic", "auto"
.auto_switching(true) // 启用自动切换
.platform_optimized(true) // 启用平台优化
.metrics_window_size(100) // 指标窗口大小
.switch_cooldown(Duration::from_secs(5)) // 切换冷却时间
.build();
在 Cargo.toml 中可以选择性启用特性:
[dependencies]
rat_congestion = { version = "0.1.0", features = ["bbr", "cubic", "platform-optimized", "simd"] }
bbr: 启用 BBR 算法(默认启用)cubic: 启用 CUBIC 算法(默认启用)platform-optimized: 启用平台特定优化simd: 启用 SIMD 指令优化项目包含多个示例,展示不同的使用场景:
cargo run --example basic_usage
展示基本的拥塞控制功能,包括:
cargo run --example advanced_scenarios
演示高级功能,包括:
cargo run --example performance_comparison
比较不同算法在各种网络条件下的性能:
NetworkMetrics 和 MetricsWindow 接口fastrand 库用于模拟网络条件当前版本: 0.1.0
如有问题或建议,请通过GitHub Issues联系开发团队。
本项目采用LGPL v3许可证。详见LICENSE文件。
RAT Congestion Control - 高性能网络拥塞控制库