Need help with weighted?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

145 Stars 36 Forks Apache License 2.0 21 Commits 2 Opened issues


high-performance common weighted algorithm library

Services available


Need anything else?

Contributors list

# 3,654
15 commits
# 233,398
1 commit

License GoDoc travis coveralls Go Report Card

rust version: weighted-rs

Package weighted implements the smooth weighted round-robin balancing algorithm. This algorithm is implemented in Nginx:

Notice: The weighted is NOT goroutine-safe so you MUST use the synchronization primitive to protect it (the Next method) in concurrent cases.

Algorithm is as follows: on each peer selection we increase currentweight of each eligible peer by its weight, select peer with greatest currentweight and reduce its current_weight by total number of weight points distributed among peers.

In case of { 5, 1, 1 } weights this gives the following sequence of current_weight's: (a, a, b, a, c, a, a)

This is an example to use it:

package main

import "fmt"

func ExampleW1_Next() { w := &SW{} w.Add("a", 5) w.Add("b", 2) w.Add("c", 3)

for i := 0; i < 10; i++ {
    fmt.Printf("%s ", w.Next())


And this lib has provides another weighted round robin algorithm. This algorithm is used in LVS. It has better performance but it is not so more smooth than the first algorithm, so you can select one algorithm according to your case. It is used like the first:

package main

import "fmt"

func ExampleW2_Next() { w := &W2{} w.Add("a", 5) w.Add("b", 2) w.Add("c", 3)

for i := 0; i < 10; i++ {
    fmt.Printf("%s ", w.Next())


We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.