public async Task LoadTest() { var port = NextPort; const int MaxUserId = 100; const int TotalMessageCount = 5000; var serializer = new XmlSerializer(); using (var server = new Server(new TcpListener(new IPEndPoint(IPAddress.Loopback, port), new TestHandshaker()), serializer)) { server.Initialize(); var clients = new Dictionary <string, Client>(); for (var i = 0; i < MaxUserId; i++) { var name = i.ToString(); var client = new LoadTestClient(MaxUserId, CreateConnectionCreator(name), serializer); await client.Connect("localhost:" + port); clients.Add(name, client); } Console.WriteLine("All clients connected"); var tasks = GenerateRequestTasks(clients, MaxUserId, TotalMessageCount); var sw = new Stopwatch(); sw.Start(); try { await Task.WhenAll(tasks); } finally { sw.Stop(); foreach (var client in clients.Values) { client.Dispose(); while (client.Status != ConnectionStatus.Disconnected) { Thread.Yield(); } } Console.WriteLine(server.PacketCount + " - " + sw.Elapsed); var perSec = server.PacketCount / sw.Elapsed.TotalSeconds; Console.WriteLine($"Total : {server.PacketCount}"); Console.WriteLine($"Per Second: {perSec}"); if (perSec < 3000) { Assert.Fail($"FAILED: Per second {perSec} too slow"); } } } }
async Task Run() { Signal.OnException += (a, b) => { Console.Error.WriteLine("Signal: " + b.Message + " " + b.Exception); }; LoggerFactory.DefaultMethod = (c) => new ConsoleLogger(c); var port = Port; const int MaxUserId = 300; const int TotalMessageCount = 20000; var serializer = new XmlSerializer(); using (var server = new Server(new TcpListener(new IPEndPoint(IPAddress.Loopback, port), new TestHandshaker()), serializer)) { server.Initialize(); var clients = new Dictionary <string, Client>(); for (var i = 0; i <= MaxUserId; i++) { var name = i.ToString(); var client = new LoadTestClient(MaxUserId, CreateConnectionCreator(name), serializer); await client.Connect("localhost:" + port); clients.Add(name, client); } Console.Beep(); Console.WriteLine("All clients connected."); var tasks = GenerateRequestTasks(clients, MaxUserId, TotalMessageCount); Console.Beep(); Console.Beep(); Console.WriteLine("Starting..."); var sw = new Stopwatch(); sw.Start(); try { await Task.WhenAll(tasks); } finally { sw.Stop(); foreach (var client in clients.Values) { client.Dispose(); while (client.Status != ConnectionStatus.Disconnected) { Thread.Yield(); } } Console.WriteLine(server.PacketCount + " - " + sw.Elapsed); var perSec = server.PacketCount / sw.Elapsed.TotalSeconds; Console.WriteLine($"Total : {server.PacketCount}"); Console.WriteLine($"Per Second: {perSec}"); if (perSec < 3000) { Console.Error.WriteLine($"FAILED: Per second {perSec} too slow"); } } } }