Browse Source

【优化】优化ice断线重连,消息重发机制

meijun 3 years ago
parent
commit
d69c5ca116

+ 4 - 4
Common/CommonAI/ZoneServer/JSGModule/JSGServerProfile.cs

@@ -49,7 +49,7 @@ namespace CommonAI.ZoneServer.JSGModule
 		}
 
 		protected static readonly Logger log = LoggerFactory.GetDefLogger();
-		private static int STRIGGER_INTERVAL = 1800 * 1000;
+		private static int STRIGGER_INTERVAL = 2 * 3600 * 1000;
 
 		//////////////////////////////////////////////////////////////////////////////////
 		//数据统计		
@@ -176,9 +176,9 @@ namespace CommonAI.ZoneServer.JSGModule
 			long curTime = CommonLang.TimeUtil.GetTimestampMS();
 			foreach (JSGTriggerProfile info in mZoneTriggers.Values)
 			{
-				JSGPrintLog("##触发器总揽:" + info.areaId + ", 运行:" + (curTime - info.areaCreateTime) + ", 创建时间:" + info.areaCreateTime + 
-					", 检测数:" + info.total.checkTimes + ", 触发数: " + info.total.triggerTimes + ", 耗时:" + info.total.timeUse);
-				if (info.total.checkTimes > 50000 || info.total.timeUse > 500)
+				JSGPrintLog("##触发器总揽: " + info.areaId + ", 运行: " + (curTime - info.areaCreateTime) + ", 创建时间: " + info.areaCreateTime +
+					", 检测数: " + info.total.checkTimes + ", 触发数: " + info.total.triggerTimes + ", 耗时: " + info.total.timeUse);
+				if (info.total.checkTimes > 300000 || info.total.timeUse > 1000 || info.total.triggerTimes > 50000)
 				{
 					foreach (KeyValuePair<string, TriggerData> kv in info.profileData)
 					{

+ 66 - 7
Common/Pomelo/PomeloShare/IceManager.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using Ice;
 using System.Web.Helpers;
 using CommonLang;
+using System.Collections.Concurrent;
 
 namespace Pomelo
 {
@@ -72,18 +73,36 @@ namespace Pomelo
 
     }
 
+    /** ice通知消息信息 */
+    public class ICENotifyData
+    {
+        public string name;
+        public string jsonData;             // 通知数据
+        public long failTime;               // 失败时间
+
+        public ICENotifyData(string name, string jsonData)
+        {
+            this.name = name;
+            this.jsonData = jsonData;
+            this.failTime = CommonLang.TimeUtil.GetTimestampMS();
+        }
+    }
+
     public class ICEZoneSession
     {
 		private CommonLang.Log.Logger log = CommonLang.Log.LoggerFactory.GetLogger("ICEZoneSession");
 
+        public ZoneManagerCallbackPrx client;
 		public ZoneManagerCallbackPrx callback;
 		public IFastSession fastSession;
 		public int failTimes = 0;
+        public ConcurrentQueue<ICENotifyData> notifyFailData = new ConcurrentQueue<ICENotifyData>();
 
-		public ICEZoneSession(ZoneManagerCallbackPrx callback)
+		public ICEZoneSession(ZoneManagerCallbackPrx client, ZoneManagerCallbackPrx callback)
         {
 			try
 			{
+                this.client = client;
 				this.callback = callback;
 				this.failTimes = 0;
 			}
@@ -99,12 +118,50 @@ namespace Pomelo
 			this.failTimes = 0;
 			return true;
 		}
+
+        /** 重新通知所有时间 */
+        public void RetryFailNotifys()
+        {
+            try
+            {
+                this.callback.ice_ping();
+            }
+            catch (System.Exception e)
+            {
+                log.Warn("RetryFailNotifys ping 异常:", e);
+            }
+
+            try
+            {
+                this.callback = (ZoneManagerCallbackPrx)client.ice_oneway();
+                log.Info("RetryFailNotifys start begin 1: " + notifyFailData.Count);
+                this.callback.ice_ping();
+                long ltimeEnd = CommonLang.TimeUtil.GetTimestampMS() - 120000;
+                while (notifyFailData.Count > 0)
+                {
+                    ICENotifyData notifyData = new ICENotifyData("", "");
+                    if (notifyFailData.TryDequeue(out notifyData) && ltimeEnd < notifyData.failTime)
+                    {
+                        log.Info("RetryFailNotifys start begin 2: " + notifyFailData.Count + ", " + notifyData.name + ", " + notifyData.jsonData + ", time: " + notifyData.failTime);
+                        this.callback.eventNotify(notifyData.name, notifyData.jsonData);
+                    }
+                    else
+                    {
+                        log.Info("RetryFailNotifys start begin 3 skip: " + notifyFailData.Count + ", " + notifyData.name + ", " + notifyData.jsonData + ", time: " + notifyData.failTime);
+                    }
+                }
+            }
+            catch(System.Exception e)
+            {
+                log.Error("RetryFailNotifys catch: " + e.Message, e);
+            }
+        }
+
     }
 
     public class IceManager : Ice.Application
     {
         private static IceManager _instance;
-
         private CommonLang.Log.Logger log = CommonLang.Log.LoggerFactory.GetLogger("IceManager");
         private Dictionary<string, Ice.ObjectImpl> proxys;
 
@@ -120,7 +177,7 @@ namespace Pomelo
                 return callbacks.Get(gameServerId);
             }
         }
-        public int setCallback(string gameServerId, ZoneManagerCallbackPrx callback)
+        public int setCallback(string gameServerId, ZoneManagerCallbackPrx client, ZoneManagerCallbackPrx callback)
         {
             lock (callbacks)
             {
@@ -137,12 +194,14 @@ namespace Pomelo
 					{
 						log.Error("ice连入,远端已经失效,重新设置!");
 						cacheSession.callback = callback;
-						return 0;
+                        //cacheSession.RetryFailNotifys();
+
+                        return 0;
 					}
 				}
                 else
                 {					
-					callbacks.Put(gameServerId, new ICEZoneSession(callback));
+					callbacks.Put(gameServerId, new ICEZoneSession(client, callback));
                 }
             }
 
@@ -231,11 +290,11 @@ namespace Pomelo
             initData.properties.setProperty("Ice.ThreadPool.Server.Size", "4");
             initData.properties.setProperty("Ice.ThreadPool.Server.SizeMax", "8");
             initData.properties.setProperty("Ice.MessageSizeMax", "10240");
-			//initData.properties.setProperty("Ice.RetryIntervals", "0 500 2000 5000");
+			initData.properties.setProperty("Ice.RetryIntervals", "0 500 2000 5000");
 
 			initData.properties.setProperty("Ice.Trace.Network", config.isTraceNetwork ? "1" : "0");
             initData.properties.setProperty("Ice.Trace.Protocol", config.isTraceProtocol ? "1" : "0");
-			//initData.properties.setProperty("Ice.Trace.Retry", "2");
+			initData.properties.setProperty("Ice.Trace.Retry", "2");
 
 			var thread = new System.Threading.Thread(() =>
             {

+ 15 - 2
Common/Pomelo/PomeloShare/ZoneManagerI.cs

@@ -28,14 +28,27 @@ namespace Pomelo
 				return 2;
 			}
 
+            //current__.con.setCallback();
             Ice.ObjectPrx @base = current__.con.createProxy(ident);
             ZoneManagerCallbackPrx client = ZoneManagerCallbackPrxHelper.uncheckedCast(@base);
-            int resCode = IceManager.instance().setCallback(ident.name, (ZoneManagerCallbackPrx)client.ice_oneway());
+            int resCode = IceManager.instance().setCallback(ident.name, client, (ZoneManagerCallbackPrx)client.ice_oneway());
 			zone.SetCallBack(ident.name);
 			return resCode;
         }
 
-		public override void createZoneRequest_async(AMD_ZoneManager_createZoneRequest cb__, string playerId, string gameServerId, 
+        public void closed(Ice.Connection con)
+        {
+            try
+            {
+                
+            }
+            catch (Ice.LocalException)
+            {
+                // The client already destroyed this session, or the server is shutting down
+            }
+        }
+
+        public override void createZoneRequest_async(AMD_ZoneManager_createZoneRequest cb__, string playerId, string gameServerId, 
 			int mapTemplateId, string instanceId, bool forceCreate, string data, Current current__)
         {
             try

+ 16 - 12
XmdsServerCS/XmdsServerNode/Node/ServerZoneNode.cs

@@ -115,25 +115,29 @@ namespace XmdsServerNode.Node
                 this.Callback = IceManager.instance().getCallback(this.BindGameServerId);
                 log.Warn("SendToGameServer callback - 1 - null : " + this.BindGameServerId + ", name:" + name + ", data:" + param);
             }
-
+            string json = null;
             if (Callback != null && Callback.callback != null)
             {
 				try
                 {
-					//ZoneManagerCallbackPrxHelper temp = (ZoneManagerCallbackPrxHelper)Callback.callback;
-					//Ice.AsyncResult<Ice.Callback_Object_ice_getConnection> test1 = Callback.callback.begin_ice_getConnection();
-					//Ice.AsyncResult test2 = Callback.callback.begin_ice_getConnection();
-					//Ice.AsyncResult<Ice.Callback_Object_ice_ping> test3 = Callback.callback.begin_ice_ping();
-					//Ice.Connection test4 = Callback.callback.ice_getCachedConnection();
-					//Ice.Communicator test5 = Callback.callback.ice_getCommunicator();
-					//Callback.callback.ice_ping();
-					string json = Json.Encode(param);
+					json = Json.Encode(param);
                     Callback.callback.eventNotify(name, json);
+
+                    //处理失败的逻辑
+                    Callback.RetryFailNotifys();
                 }
 				catch (Exception err)
 				{
-					log.Error(err.Message, err);
-					EventNotifyFail();
+                    if(json == null)
+                    {
+                        log.Error("SendToGameServer序列化就异常了,放弃记录:" + name + ", err:" + err.Message, err);
+                    }
+                    else
+                    {
+                        Callback.notifyFailData.Enqueue(new ICENotifyData(name, json));
+                        log.Error("SendToGameServer: " + name + ", err:" + err.Message, err);
+                        EventNotifyFail();                        
+                    }
 				}
 			}
             else
@@ -149,7 +153,7 @@ namespace XmdsServerNode.Node
 				if (Callback.callback.ice_getCachedConnection() == null)
 				{
 					Callback.failTimes++;
-					if (Callback.fastSession != null && Callback.failTimes >= 3)
+					if (Callback.fastSession != null/* && Callback.failTimes >= 3*/)
 					{
 						Callback.fastSession.doClose();
 						Callback.failTimes = 0;