refactor
This commit is contained in:
parent
2066723e71
commit
71beaa0190
|
@ -137,19 +137,21 @@ func (policy *WeightRoundRobinPolicy) Slave(g *EngineGroup) *Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LeastConnPolicy implements GroupPolicy, every time will get the least connections slave
|
// LeastConnPolicy implements GroupPolicy, every time will get the least connections slave
|
||||||
var LeastConnPolicy GroupPolicyHandler = func(g *EngineGroup) *Engine {
|
func LeastConnPolicy() GroupPolicyHandler {
|
||||||
var slaves = g.Slaves()
|
return func(g *EngineGroup) *Engine {
|
||||||
connections := 0
|
var slaves = g.Slaves()
|
||||||
idx := 0
|
connections := 0
|
||||||
for i, _ := range slaves {
|
idx := 0
|
||||||
open_connections := slaves[i].DB().Stats().OpenConnections
|
for i := 0; i < len(slaves); i++ {
|
||||||
if i == 0 {
|
openConnections := slaves[i].DB().Stats().OpenConnections
|
||||||
connections = open_connections
|
if i == 0 {
|
||||||
idx = i
|
connections = openConnections
|
||||||
} else if open_connections <= connections {
|
idx = i
|
||||||
connections = open_connections
|
} else if openConnections <= connections {
|
||||||
idx = i
|
connections = openConnections
|
||||||
|
idx = i
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return slaves[idx]
|
||||||
}
|
}
|
||||||
return slaves[idx]
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue