#weight #weighted #balancing

weighted-rs

A libray for weighted balancing algorithm

3 releases

0.1.2 Sep 16, 2019
0.1.1 Sep 1, 2019
0.1.0 Aug 30, 2019

#593 in Algorithms

Download history 40/week @ 2021-02-15 25/week @ 2021-02-22 43/week @ 2021-03-01 40/week @ 2021-03-08 23/week @ 2021-03-15 65/week @ 2021-03-22 56/week @ 2021-03-29 78/week @ 2021-04-05 100/week @ 2021-04-12 75/week @ 2021-04-19 34/week @ 2021-04-26 42/week @ 2021-05-03 77/week @ 2021-05-10 58/week @ 2021-05-17 54/week @ 2021-05-24 93/week @ 2021-05-31

231 downloads per month
Used in 3 crates (2 directly)

MIT license

15KB
330 lines

weight-rs

Build Status Crate API

A Rust library for weighted balancing algorithm.

It provides three weighted balancing (elect) algorithm. One is random algorithm. Another is weighted balancing algorithm used by LVS. The third is smooth weighted balancing algorithm used by Nginx.

The LVS weighted round-robin scheduling is introduced at http://kb.linuxvirtualserver.org/wiki/Weighted_Round-Robin_Scheduling. The Nginx smooth weighted round-robin balancing algorithm is introduced at https://github.com/phusion/nginx/commit/27e94984486058d73157038f7950a0a36ecc6e35. The random algorithm is not smooth although it follows weight configuration.

Using it is simple:

    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);
    }

Usage

Add this to your Cargo.toml:

[dependencies]
weighted-rs = "0.1.1"

License

weighted-rs is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT, and COPYRIGHT for details.

Dependencies

~340KB