#weighted #balancing #weight

weighted-rs-1

加权平衡算法库

1个不稳定版本

0.1.4 2022年2月14日

#1988算法

MIT 许可证

13KB
245

weight-rs

Build Status Crate API

一个用于加权平衡算法的Rust库。

它提供了三种加权平衡(选举)算法。一种是LVS使用的加权平衡算法。另一种是Nginx使用的平滑加权平衡算法。

LVS的加权轮询调度介绍在http://kb.linuxvirtualserver.org/wiki/Weighted_Round-Robin_Scheduling。Nginx的平滑加权轮询平衡算法介绍在https://github.com/phusion/nginx/commit/27e94984486058d73157038f7950a0a36ecc6e35

使用简单

    use weighted_rs_wasm::{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-APACHELICENSE-MITCOPYRIGHT 了解详细信息。

无运行时依赖