Crate weighted_rs[][src]

Expand description

A libray 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 The Nginx smooth weighted round-robin balancing algorithm is introduced at 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 =;
        println!("{}", s);


pub use random_weight::*;
pub use roundrobin_weight::*;
pub use smooth_weight::*;