4个版本
0.1.3 | 2021年8月25日 |
---|---|
0.1.2 | 2019年9月16日 |
0.1.1 | 2019年9月1日 |
0.1.0 | 2019年8月30日 |
#605 在 算法 分类中
1,987 每月下载次数
被 5 个crate(其中4个直接使用) 使用
16KB
330 行
weight-rs
一个用于加权平衡算法的Rust库。
它提供了三种加权平衡(选举)算法。一种是随机算法。另一种是LVS使用的加权平衡算法。第三种是Nginx使用的平滑加权平衡算法。
LVS加权轮询调度介绍在 http://kb.linuxvirtualserver.org/wiki/Weighted_Round-Robin_Scheduling。Nginx平滑加权轮询平衡算法介绍在 https://github.com/phusion/nginx/commit/27e94984486058d73157038f7950a0a36ecc6e35。随机算法虽然遵循权重配置,但不是平滑的。
使用很简单
use weighted-rs::{SmoothWeight, Weight};
use std::collections::HashMap;
let mut sw: SmoothWeight<&str> = SmoothWeight::new();
sw.add("server1", 5);
sw.add("server2", 2);
sw.add("server3", 3);
for _ in 0..100 {
let s = sw.next().unwrap();
println!("{}", s);
}
用法
将以下内容添加到您的 Cargo.toml
[dependencies]
weighted-rs = "0.1.1"
许可证
weighted-rs在MIT许可证和Apache许可证(版本2.0)的条款下分发。
请参阅 LICENSE-APACHE、LICENSE-MIT 和 COPYRIGHT 以获取详细信息。
依赖
~305KB