Merge branch 'group-engine' of https://github.com/WhiteBatman/xorm into WhiteBatman/group-engine
This commit is contained in:
commit
3981aa9b1a
|
@ -73,6 +73,9 @@ func (eg *EngineGroup) Slave() *Engine {
|
||||||
case 1:
|
case 1:
|
||||||
return eg.slaves[0]
|
return eg.slaves[0]
|
||||||
}
|
}
|
||||||
|
if eg.s_count == 1 {
|
||||||
|
return eg.slaves[0]
|
||||||
|
}
|
||||||
return eg.policy.Slave(eg)
|
return eg.policy.Slave(eg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ func (policy *RoundRobinPolicy) Slave(g *EngineGroup) *Engine {
|
||||||
var pos int
|
var pos int
|
||||||
policy.lock.Lock()
|
policy.lock.Lock()
|
||||||
policy.pos++
|
policy.pos++
|
||||||
if policy.pos >= len(g.Slaves()) {
|
if policy.pos >= g.s_count {
|
||||||
policy.pos = 0
|
policy.pos = 0
|
||||||
}
|
}
|
||||||
pos = policy.pos
|
pos = policy.pos
|
||||||
|
@ -130,6 +130,18 @@ func NewLeastConnPolicy() *LeastConnPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (policy *LeastConnPolicy) Slave(g *EngineGroup) *Engine {
|
func (policy *LeastConnPolicy) Slave(g *EngineGroup) *Engine {
|
||||||
panic("not implementation")
|
var slaves = g.Slaves()
|
||||||
return nil
|
connections := 0
|
||||||
|
idx := 0
|
||||||
|
for i, _ := range slaves {
|
||||||
|
open_connections := slaves[i].Stats()
|
||||||
|
if i == 0 {
|
||||||
|
connections = open_connections
|
||||||
|
idx = i
|
||||||
|
} else if open_connections <= connections {
|
||||||
|
connections = open_connections
|
||||||
|
idx = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return slaves[idx]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue