forked from smallnest/weighted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweighted.go
26 lines (22 loc) · 1.04 KB
/
weighted.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
Package weighted implements two weighted round robin algorithms.
One is the smooth weighted round-robin balancing algorithm used in Nginx, and you can use "w := new SW{}" to use it.
The other is wrr used in LVS and you can use "w := new RRW{}" to use it.
For Nginx smooth weighted round-robin balancing algorithm, you can check https://github.com/phusion/nginx/commit/27e94984486058d73157038f7950a0a36ecc6e35.
For LVS round-robin balancing algorithm, you can check http://kb.linuxvirtualitem.org/wiki/Weighted_Round-Robin_Scheduling.
*/
package weighted
// W is a interface that implement a weighted round robin algorithm.
type W interface {
// Next gets next selected item.
// Next is not goroutine-safe. You MUST use the snchronization primitive to protect it in concurrent cases.
Next() (item interface{})
// Add adds a weighted item for selection.
Add(item interface{}, weight int)
// All returns all items.
All() map[interface{}]int
// RemoveAll removes all weighted items.
RemoveAll()
// Reset resets the balancing algorithm.
Reset()
}