提交 ef8d2262 编写于 作者: T tanghai

使用protobuf序列化可能是空byte[], 修复benchmark的问题,1000个连接,每秒约4W包

上级 5458ee77
......@@ -105,7 +105,7 @@ namespace App
break;
case AppType.Benchmark:
Game.Scene.AddComponent<NetOuterComponent>();
Game.Scene.AddComponent<BenchmarkComponent, string>(clientConfig.Address);
Game.Scene.AddComponent<BenchmarkComponent, IPEndPoint>(clientConfig.IPEndPoint);
break;
default:
throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
......
......@@ -24,7 +24,7 @@ namespace Model
try
{
NetOuterComponent networkComponent = Game.Scene.GetComponent<NetOuterComponent>();
for (int i = 0; i < 100; i++)
for (int i = 0; i < 1000; i++)
{
await Game.Scene.GetComponent<TimerComponent>().WaitAsync(1000);
this.TestAsync(networkComponent, ipEndPoint, i);
......@@ -43,10 +43,9 @@ namespace Model
using (Session session = networkComponent.Create(ipEndPoint))
{
int i = 0;
while (i < 100000000)
while (i < 1000000000)
{
++i;
await Game.Scene.GetComponent<TimerComponent>().WaitAsync(10);
await this.Send(session, j);
}
}
......@@ -68,7 +67,7 @@ namespace Model
await session.Call<R2C_Ping>(new C2R_Ping());
++this.k;
if (this.k % 10000 != 0)
if (this.k % 100000 != 0)
{
return;
}
......
using MongoDB.Bson.Serialization.Attributes;
using System.Net;
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
......@@ -16,5 +17,14 @@ namespace Model
return $"{this.Host}:{this.Port}";
}
}
[BsonIgnore]
public IPEndPoint IPEndPoint
{
get
{
return NetworkHelper.ToIPEndPoint(this.Host, this.Port);
}
}
}
}
\ No newline at end of file
......@@ -13,6 +13,7 @@ namespace Model
[ProtoInclude((int)Opcode.C2R_Login, typeof(C2R_Login))]
[ProtoInclude((int)Opcode.C2G_LoginGate, typeof(C2G_LoginGate))]
[ProtoInclude((int)Opcode.C2G_EnterMap, typeof(C2G_EnterMap))]
[ProtoInclude((int)Opcode.C2R_Ping, typeof(C2R_Ping))]
public abstract partial class ARequest : AMessage
{
}
......@@ -21,6 +22,7 @@ namespace Model
[ProtoInclude((int)Opcode.R2C_Login, typeof(R2C_Login))]
[ProtoInclude((int)Opcode.G2C_LoginGate, typeof(G2C_LoginGate))]
[ProtoInclude((int)Opcode.G2C_EnterMap, typeof(G2C_EnterMap))]
[ProtoInclude((int)Opcode.R2C_Ping, typeof(R2C_Ping))]
public abstract partial class AResponse : AMessage
{
}
......@@ -198,11 +200,13 @@ namespace Model
{
}
[ProtoContract]
[Message(Opcode.C2R_Ping)]
public class C2R_Ping: ARequest
{
}
[ProtoContract]
[Message(Opcode.R2C_Ping)]
public class R2C_Ping: AResponse
{
......
......@@ -62,9 +62,9 @@ namespace Model
continue;
}
if (messageBytes.Length < 3)
if (messageBytes.Length < 2)
{
Log.Error($"message error length < 3, ip: {this.RemoteAddress}");
Log.Error($"message error length < 2, ip: {this.RemoteAddress}");
this.network.Remove(this.Id);
return;
}
......@@ -131,7 +131,7 @@ namespace Model
{
request.RpcId = ++RpcId;
this.requestCallback[RpcId] = (message) =>
this.requestCallback[request.RpcId] = (message) =>
{
try
{
......@@ -155,7 +155,7 @@ namespace Model
request.RpcId = ++RpcId;
var tcs = new TaskCompletionSource<AResponse>();
this.requestCallback[RpcId] = (message) =>
this.requestCallback[request.RpcId] = (message) =>
{
try
{
......@@ -187,7 +187,7 @@ namespace Model
var tcs = new TaskCompletionSource<AResponse>();
this.requestCallback[RpcId] = (message) =>
this.requestCallback[request.RpcId] = (message) =>
{
try
{
......@@ -206,7 +206,7 @@ namespace Model
}
};
cancellationToken.Register(() => { this.requestCallback.Remove(RpcId); });
cancellationToken.Register(() => { this.requestCallback.Remove(request.RpcId); });
this.SendMessage(request);
......@@ -221,7 +221,7 @@ namespace Model
request.RpcId = ++RpcId;
var tcs = new TaskCompletionSource<Response>();
this.requestCallback[RpcId] = (message) =>
this.requestCallback[request.RpcId] = (message) =>
{
try
{
......@@ -255,7 +255,7 @@ namespace Model
var tcs = new TaskCompletionSource<Response>();
this.requestCallback[RpcId] = (message) =>
this.requestCallback[request.RpcId] = (message) =>
{
try
{
......@@ -274,7 +274,7 @@ namespace Model
}
};
cancellationToken.Register(() => { this.requestCallback.Remove(RpcId); });
cancellationToken.Register(() => { this.requestCallback.Remove(request.RpcId); });
this.SendMessage(request);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册