Преглед изворни кода

增加Ping Pong测试,
1.使用TCP协议测试,10W次Rpc调用, windows平均耗时4S左右, linux下平均耗时5.6S
2.使用UDP协议测试,10W次Rpc调用, windows平均耗时4S左右, linux下平均耗时3S

tanghai пре 9 година
родитељ
комит
a0c3823347

+ 15 - 0
Server/Controller/Message/C2R_PingHandler.cs

@@ -0,0 +1,15 @@
+using System;
+using Model;
+
+namespace Controller
+{
+	[MessageHandler(AppType.Realm)]
+	public class C2R_PingHandler : AMRpcHandler<C2R_Ping, R2C_Ping>
+	{
+		protected override void Run(Session session, C2R_Ping message, Action<R2C_Ping> reply)
+		{
+			R2C_Ping r2CPing = new R2C_Ping();
+			reply(r2CPing);
+		}
+	}
+}

+ 1 - 0
Server/Controller/Server.Controller.csproj

@@ -35,6 +35,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Message\C2G_LoginGateHandler.cs" />
+    <Compile Include="Message\C2R_PingHandler.cs" />
     <Compile Include="Message\M2A_ReloadHandler.cs" />
     <Compile Include="Message\C2M_ReloadHandler.cs" />
     <Compile Include="Message\R2G_GetLoginKeyHandler.cs" />

+ 12 - 11
Unity/Assets/Scripts/Component/BenchmakComponent.cs

@@ -17,12 +17,15 @@ namespace Model
 	{
 		private int k;
 
-		public void Awake(string address)
+		private long time1 = TimeHelper.ClientNowTicks();
+
+		public async void Awake(string address)
 		{
 			NetOuterComponent networkComponent = Game.Scene.GetComponent<NetOuterComponent>();
 
-			for (int i = 0; i < 400; i++)
+			for (int i = 0; i < 100; i++)
 			{
+				await Game.Scene.GetComponent<TimerComponent>().WaitAsync(10);
 				TestAsync(networkComponent, address, i);
 			}
 		}
@@ -32,22 +35,20 @@ namespace Model
 			using (Session session = networkComponent.Create(address))
 			{
 				int i = 0;
-				while (i < 10000)
+				while (i < 10000000)
 				{
 					++i;
 					try
 					{
-						R2C_Login s2CLogin = await session.Call<C2R_Login, R2C_Login>(new C2R_Login { Account = "abcdef", Password = "111111" });
-
-						using (Session gateSession = networkComponent.Create(s2CLogin.Address))
-						{
-							await gateSession.Call<C2G_LoginGate, G2C_LoginGate>(new C2G_LoginGate(s2CLogin.Key));
-						}
+						await session.Call<C2R_Ping, R2C_Ping>(new C2R_Ping());
 
 						++this.k;
-						if (this.k % 1000 == 0)
+						if (this.k % 100000 == 0)
 						{
-							Log.Info($"{j} Benchmark k: {k}");
+							long time2 = TimeHelper.ClientNowTicks();
+							long time = time2 - this.time1;
+							this.time1 = time2;
+							Log.Info($"{j} Benchmark k: {k} 每10W次耗时: {time}");
 						}
 					}
 					catch (RpcException e)

+ 12 - 0
Unity/Assets/Scripts/Entity/Message/Message.cs

@@ -111,4 +111,16 @@ namespace Model
 	public class A2M_Reload : AResponse
 	{
 	}
+
+	[Message(14)]
+	[BsonIgnoreExtraElements]
+	public class C2R_Ping : ARequest
+	{
+	}
+
+	[Message(15)]
+	[BsonIgnoreExtraElements]
+	public class R2C_Ping : AResponse
+	{
+	}
 }