mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +08:00
优化rpc-减少gc
This commit is contained in:
@@ -182,24 +182,25 @@ func (cls *Cluster) GetRpcClient(nodeId int) *rpc.Client {
|
||||
return c.client
|
||||
}
|
||||
|
||||
func GetRpcClient(nodeId int,serviceMethod string,clientList *[]*rpc.Client) error {
|
||||
func GetRpcClient(nodeId int,serviceMethod string,clientList []*rpc.Client) (error,int) {
|
||||
if nodeId>0 {
|
||||
pClient := GetCluster().GetRpcClient(nodeId)
|
||||
if pClient==nil {
|
||||
return fmt.Errorf("cannot find nodeid %d!",nodeId)
|
||||
return fmt.Errorf("cannot find nodeid %d!",nodeId),0
|
||||
}
|
||||
*clientList = append(*clientList,pClient)
|
||||
return nil
|
||||
clientList[0] = pClient
|
||||
return nil,1
|
||||
}
|
||||
|
||||
serviceAndMethod := strings.Split(serviceMethod,".")
|
||||
if len(serviceAndMethod)!=2 {
|
||||
return fmt.Errorf("servicemethod param %s is error!",serviceMethod)
|
||||
|
||||
findIndex := strings.Index(serviceMethod,".")
|
||||
if findIndex==-1 {
|
||||
return fmt.Errorf("servicemethod param %s is error!",serviceMethod),0
|
||||
}
|
||||
serviceName := serviceMethod[:findIndex]
|
||||
|
||||
//1.找到对应的rpcNodeid
|
||||
GetCluster().GetNodeIdByService(serviceAndMethod[0],clientList)
|
||||
return nil
|
||||
return GetCluster().GetNodeIdByService(serviceName,clientList)
|
||||
}
|
||||
|
||||
func GetRpcServer() *rpc.Server{
|
||||
|
||||
@@ -194,10 +194,11 @@ func (cls *Cluster) IsConfigService(serviceName string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (cls *Cluster) GetNodeIdByService(serviceName string,rpcClientList *[]*rpc.Client) {
|
||||
func (cls *Cluster) GetNodeIdByService(serviceName string,rpcClientList []*rpc.Client) (error,int) {
|
||||
cls.locker.RLock()
|
||||
defer cls.locker.RUnlock()
|
||||
nodeIdList,ok := cls.mapServiceNode[serviceName]
|
||||
count := 0
|
||||
if ok == true {
|
||||
for _,nodeId := range nodeIdList {
|
||||
pClient := GetCluster().GetRpcClient(nodeId)
|
||||
@@ -205,9 +206,15 @@ func (cls *Cluster) GetNodeIdByService(serviceName string,rpcClientList *[]*rpc.
|
||||
log.Error("Cannot connect node id %d",nodeId)
|
||||
continue
|
||||
}
|
||||
*rpcClientList = append(*rpcClientList,pClient)
|
||||
rpcClientList[count] = pClient
|
||||
count++
|
||||
if count>=cap(rpcClientList) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil,count
|
||||
}
|
||||
|
||||
func (cls *Cluster) getServiceCfg(serviceName string) interface{}{
|
||||
|
||||
Reference in New Issue
Block a user