weighted-rs-1

Crates.ioweighted-rs-1
lib.rsweighted-rs-1
version0.1.4
sourcesrc
created_at2022-02-14 07:22:57.80394
updated_at2022-02-14 07:22:57.80394
descriptionA libray for weighted balancing algorithm.
homepagehttps://crates.io/crates/weighted-rs
repositoryhttps://github.com/nhtera/weighted-rs
max_upload_size
id532093
size14,398
Tien Nguyen (nhtera)

documentation

https://docs.rs/weighted-rs/

README

weight-rs

Build Status Crate API

A Rust library for weighted balancing algorithm.

It provides three weighted balancing (elect) algorithm. One is weighted balancing algorithm used by LVS. Another 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.

Using it is simple:

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

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.

Commit count: 11

cargo fmt