Pārlūkot izejas kodu

修复一个ThreadPool调度的bug,每次跑完都sleep,导致纤程过多的时候严重影响性能,应该只在没有纤程的时候sleep

tanghai 2 gadi atpakaļ
vecāks
revīzija
861dd70acb

+ 7 - 2
Unity/Assets/Scripts/Core/Network/IKcpTransport.cs

@@ -13,6 +13,7 @@ namespace ET
         int Recv(byte[] buffer, ref EndPoint endPoint);
         int Available();
         void Update();
+        void OnError(long id, int error);
     }
 
     public class UdpTransport: IKcpTransport
@@ -65,6 +66,10 @@ namespace ET
         {
         }
 
+        public void OnError(long id, int error)
+        {
+        }
+
         public void Dispose()
         {
             this.socket?.Dispose();
@@ -107,9 +112,9 @@ namespace ET
             this.idEndpoints.Add(id, channel.RemoteAddress);
         }
 
-        private void OnError(long id, int error)
+        public void OnError(long id, int error)
         {
-            Log.Warning($"IKcpTransport tcp error: {error}");
+            Log.Warning($"IKcpTransport tcp error: {id} {error}");
             this.tService.Remove(id, error);
             this.idEndpoints.RemoveByKey(id);
             this.readWriteTime.Remove(id);

+ 1 - 0
Unity/Assets/Scripts/Core/Network/KService.cs

@@ -460,6 +460,7 @@ namespace ET
             }
             
             kChannel.Dispose();
+            this.Transport.OnError(id, error);
         }
 
         public void Disconnect(uint localConn, uint remoteConn, int error, EndPoint address, int times)

+ 0 - 2
Unity/Assets/Scripts/Core/World/Module/Fiber/ThreadPoolScheduler.cs

@@ -60,8 +60,6 @@ namespace ET
                 Fiber.Instance = null;
 
                 this.idQueue.Enqueue(id);
-
-                Thread.Sleep(1);
             }
         }
 

+ 8 - 0
Unity/Assets/Scripts/Hotfix/Server/Demo/Realm/C2R_LoginHandler.cs

@@ -20,6 +20,14 @@ namespace ET.Server
 			response.Address = config.InnerIPPort.ToString();
 			response.Key = g2RGetLoginKey.Key;
 			response.GateId = g2RGetLoginKey.GateId;
+			
+			CloseSession(session).Coroutine();
+		}
+
+		private async ETTask CloseSession(Session session)
+		{
+			await session.Fiber().TimerComponent.WaitAsync(1000);
+			session.Dispose();
 		}
 	}
 }