mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-06 01:50:26 +08:00
优化RPC调用
This commit is contained in:
@@ -53,6 +53,7 @@ func (this *IPListManager) Start() {
|
|||||||
events.On(events.EventQuit, func() {
|
events.On(events.EventQuit, func() {
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
})
|
})
|
||||||
|
countErrors := 0
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
@@ -60,15 +61,20 @@ func (this *IPListManager) Start() {
|
|||||||
}
|
}
|
||||||
err := this.loop()
|
err := this.loop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
countErrors++
|
||||||
|
|
||||||
logs.Println("IP_LIST_MANAGER", err.Error())
|
logs.Println("IP_LIST_MANAGER", err.Error())
|
||||||
|
|
||||||
// 方便立即重试
|
// 连续错误小于3次的我们立即重试
|
||||||
|
if countErrors <= 3 {
|
||||||
select {
|
select {
|
||||||
case IPListUpdateNotify <- true:
|
case IPListUpdateNotify <- true:
|
||||||
default:
|
default:
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
countErrors = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -181,11 +181,16 @@ func (this *RPCClient) pickConn() *grpc.ClientConn {
|
|||||||
// 检查连接状态
|
// 检查连接状态
|
||||||
if len(this.conns) > 0 {
|
if len(this.conns) > 0 {
|
||||||
availableConns := []*grpc.ClientConn{}
|
availableConns := []*grpc.ClientConn{}
|
||||||
|
for _, state := range []connectivity.State{connectivity.Ready, connectivity.Idle, connectivity.Connecting} {
|
||||||
for _, conn := range this.conns {
|
for _, conn := range this.conns {
|
||||||
if conn.GetState() == connectivity.Ready {
|
if conn.GetState() == state {
|
||||||
availableConns = append(availableConns, conn)
|
availableConns = append(availableConns, conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(availableConns) > 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(availableConns) > 0 {
|
if len(availableConns) > 0 {
|
||||||
return availableConns[rands.Int(0, len(availableConns)-1)]
|
return availableConns[rands.Int(0, len(availableConns)-1)]
|
||||||
|
|||||||
Reference in New Issue
Block a user