smallnest/weighted
소개
high-performance common weighted algorithm library
개발 도구측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originalrust version: weighted-rs
Package weighted implements the smooth weighted round-robin balancing algorithm. This algorithm is implemented in Nginx: https://github.com/phusion/nginx/commit/27e94984486058d73157038f7950a0a36ecc6e35.
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 current_weight of each eligible peer by its weight, select peer with greatest current_weight 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 ExampleSW_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 ExampleRRW_Next() {
w := &RRW{}
w.Add("a", 5)
w.Add("b", 2)
w.Add("c", 3)
for i := 0; i < 10; i++ {
fmt.Printf("%s ", w.Next())
}
}
관련 프로젝트 살펴보기
불러오는 중…
