fix : writer 전역으로 변경, pendingPings 락 프리 Cuncurrent로 변경
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using ClientTester.Packet;
|
||||
using LiteNetLib;
|
||||
@@ -8,13 +9,14 @@ namespace ClientTester.EchoDummyService;
|
||||
|
||||
public class DummyClients
|
||||
{
|
||||
public NetManager manager;
|
||||
public EventBasedNetListener listener;
|
||||
private NetManager manager;
|
||||
private EventBasedNetListener listener;
|
||||
private NetDataWriter? writer;
|
||||
public NetPeer? peer;
|
||||
public int clientId;
|
||||
|
||||
// seq → 송신 타임스탬프 (Stopwatch tick)
|
||||
private readonly Dictionary<int, long> pendingPings = new();
|
||||
private ConcurrentDictionary<int, long> pendingPings = new();
|
||||
private int seqNumber;
|
||||
|
||||
// 통계
|
||||
@@ -53,6 +55,7 @@ public class DummyClients
|
||||
this.clientId = clientId;
|
||||
listener = new EventBasedNetListener();
|
||||
manager = new NetManager(listener);
|
||||
writer = new NetDataWriter();
|
||||
|
||||
listener.PeerConnectedEvent += netPeer =>
|
||||
{
|
||||
@@ -65,16 +68,16 @@ public class DummyClients
|
||||
short code = reader.GetShort();
|
||||
short bodyLength = reader.GetShort();
|
||||
string? msg = reader.GetString();
|
||||
long sentTick;
|
||||
|
||||
if (msg != null && msg.StartsWith("Echo seq:") &&
|
||||
int.TryParse(msg.Substring("Echo seq:".Length), out int seq) &&
|
||||
pendingPings.TryGetValue(seq, out long sentTick))
|
||||
pendingPings.TryRemove(seq, out sentTick))
|
||||
{
|
||||
double rttMs = (Stopwatch.GetTimestamp() - sentTick) * 1000.0 / Stopwatch.Frequency;
|
||||
LastRttMs = rttMs;
|
||||
TotalRttMs += rttMs;
|
||||
RttCount++;
|
||||
pendingPings.Remove(seq);
|
||||
}
|
||||
|
||||
ReceivedCount++;
|
||||
@@ -93,7 +96,7 @@ public class DummyClients
|
||||
|
||||
public void SendPing()
|
||||
{
|
||||
if (peer == null)
|
||||
if (peer == null || writer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -101,15 +104,16 @@ public class DummyClients
|
||||
int seq = seqNumber++;
|
||||
pendingPings[seq] = Stopwatch.GetTimestamp();
|
||||
|
||||
NetDataWriter writer = new NetDataWriter();
|
||||
PacketHeader packetHeader = new PacketHeader();
|
||||
packetHeader.Code = 0;
|
||||
packetHeader.BodyLength = $"seq:{seq}".Length;
|
||||
writer.Put((short)packetHeader.Code);
|
||||
writer.Put((short)packetHeader.BodyLength);
|
||||
writer.Put($"Echo seq:{seq}");
|
||||
peer.Send(writer, DeliveryMethod.ReliableOrdered);
|
||||
// 순서보장 안함 HOL Blocking 제거
|
||||
peer.Send(writer, DeliveryMethod.ReliableUnordered);
|
||||
SentCount++;
|
||||
writer.Reset();
|
||||
}
|
||||
|
||||
public double AvgRttMs => RttCount > 0 ? TotalRttMs / RttCount : 0.0;
|
||||
|
||||
Reference in New Issue
Block a user