#weighted #balancing #weight

weighted-rs

A libray for weighted balancing algorithm

4 releases

0.1.3 Aug 25, 2021
0.1.2 Sep 16, 2019
0.1.1 Sep 1, 2019
0.1.0 Aug 30, 2019

#617 in Algorithms

Download history 439/week @ 2024-06-04 557/week @ 2024-06-11 475/week @ 2024-06-18 652/week @ 2024-06-25 398/week @ 2024-07-02 380/week @ 2024-07-09 433/week @ 2024-07-16 512/week @ 2024-07-23 693/week @ 2024-07-30 637/week @ 2024-08-06 649/week @ 2024-08-13 482/week @ 2024-08-20 457/week @ 2024-08-27 542/week @ 2024-09-03 350/week @ 2024-09-10 332/week @ 2024-09-17

1,712 downloads per month
Used in 5 crates (4 directly)

MIT license

16KB
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

~310KB