-
Notifications
You must be signed in to change notification settings - Fork 2
/
loadbalance.go
54 lines (49 loc) · 1.4 KB
/
loadbalance.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package loadbalance
import (
"google.golang.org/grpc/balancer"
)
// Aperture support map local peers to remote peers
// to divide remote peers into subsets
// to separate services into small sets and reduce the total connections
type Aperture interface {
// Next returns next selected item.
Next() (interface{}, func(balancer.DoneInfo))
// Set logical aperture
SetLogicalAperture(int)
// Set local peer id
SetLocalPeerID(string)
// Set local peers.
SetLocalPeers([]string)
// Set remote peers.
SetRemotePeers([]interface{})
}
// SetInfo contains region, zone and set
type SetInfo struct {
// Name, app name defined as set
Name string
// Region, like `bj(beijing)` or `sh(shanghai)`
Region string
// UnitName, unit name defined as subsets
UnitName string
}
// Set supports divide remote peers into subsets
// based on region, zone and set info
type Set interface {
// Next returns next selected item.
Next() (interface{}, func(balancer.DoneInfo))
// Add a weighted item with set info.
Add(interface{}, float64, SetInfo)
// Reset this picker
Reset()
}
// Picker supports multiple algorithms for load balance,
// uses the ideas behind the "power of 2 choices"
// to select two nodes from the underlying vector.
type Picker interface {
// Next returns next selected item.
Next() (interface{}, func(balancer.DoneInfo))
// Add a weighted item.
Add(interface{}, float64)
// Reset this picker
Reset()
}