mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +08:00
优化服务发现
This commit is contained in:
@@ -175,6 +175,7 @@ func (cls *Cluster) serviceDiscoverySetNodeInfo (nodeInfo *NodeInfo){
|
|||||||
}
|
}
|
||||||
cls.mapIdNode[nodeInfo.NodeId] = *nodeInfo
|
cls.mapIdNode[nodeInfo.NodeId] = *nodeInfo
|
||||||
|
|
||||||
|
log.Debug("Discovery nodeId: %d discovery service:%+v",nodeInfo.NodeId,nodeInfo.PublicServiceList)
|
||||||
//已经存在连接,则不需要进行设置
|
//已经存在连接,则不需要进行设置
|
||||||
if _,rpcInfoOK := cls.mapRpc[nodeInfo.NodeId];rpcInfoOK == true {
|
if _,rpcInfoOK := cls.mapRpc[nodeInfo.NodeId];rpcInfoOK == true {
|
||||||
return
|
return
|
||||||
@@ -186,9 +187,7 @@ func (cls *Cluster) serviceDiscoverySetNodeInfo (nodeInfo *NodeInfo){
|
|||||||
rpcInfo.client.Connect(nodeInfo.NodeId,nodeInfo.ListenAddr)
|
rpcInfo.client.Connect(nodeInfo.NodeId,nodeInfo.ListenAddr)
|
||||||
cls.mapRpc[nodeInfo.NodeId] = rpcInfo
|
cls.mapRpc[nodeInfo.NodeId] = rpcInfo
|
||||||
|
|
||||||
//debug
|
|
||||||
fmt.Printf("xxxxxxxxxxxx")
|
|
||||||
fmt.Println(nodeInfo)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cls *Cluster) buildLocalRpc(){
|
func (cls *Cluster) buildLocalRpc(){
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ func (processor *EventProcessor) EventHandler(ev IEvent) {
|
|||||||
|
|
||||||
func (processor *EventProcessor) pushEvent(event IEvent){
|
func (processor *EventProcessor) pushEvent(event IEvent){
|
||||||
if len(processor.eventChannel)>=cap(processor.eventChannel){
|
if len(processor.eventChannel)>=cap(processor.eventChannel){
|
||||||
log.Error("event process channel is full.")
|
log.Error("event process channel is full,data:%+v!",event)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -232,12 +232,12 @@ func startNode(args interface{}) error{
|
|||||||
//2.初始化node
|
//2.初始化node
|
||||||
initNode(nodeId)
|
initNode(nodeId)
|
||||||
|
|
||||||
//3.运行集群
|
//3.运行service
|
||||||
cluster.GetCluster().Start()
|
|
||||||
|
|
||||||
//4.运行service
|
|
||||||
service.Start()
|
service.Start()
|
||||||
|
|
||||||
|
//4.运行集群
|
||||||
|
cluster.GetCluster().Start()
|
||||||
|
|
||||||
//5.记录进程id号
|
//5.记录进程id号
|
||||||
writeProcessPid(nodeId)
|
writeProcessPid(nodeId)
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ func (agent *RpcAgent) Run() {
|
|||||||
for {
|
for {
|
||||||
data,err := agent.conn.ReadMsg()
|
data,err := agent.conn.ReadMsg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("read message: %v", err)
|
log.Error("read message: %v,remoteAddress:%s", err,agent.conn.RemoteAddr().String())
|
||||||
//will close tcpconn
|
//will close tcpconn
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,8 @@ func (s *Service) SetGoRoutineNum(goroutineNum int32) bool {
|
|||||||
|
|
||||||
func (s *Service) Start() {
|
func (s *Service) Start() {
|
||||||
s.startStatus = true
|
s.startStatus = true
|
||||||
|
s.eventProcessor.SetEventChannel(0)
|
||||||
|
|
||||||
for i:=int32(0);i< s.goroutineNum;i++{
|
for i:=int32(0);i< s.goroutineNum;i++{
|
||||||
s.wg.Add(1)
|
s.wg.Add(1)
|
||||||
go func(){
|
go func(){
|
||||||
|
|||||||
Reference in New Issue
Block a user