Web套接字消息未全部收到 [英] Web Socket messages not all being received
问题描述
我已经使用 Alchemy Web套接字实现了Web套接字服务器,现在正尝试对其进行压力测试.我已经在C#中编写了以下方法,以创建大量客户端以连接到服务器并发送一些数据:
I have implemented a web socket server using Alchemy web sockets, and am now trying to stress test it. I have written the following method in C# to create numerous clients to connect to the server and send some data:
private void TestWebSocket()
{
int clients = 10;
long messages = 10000;
long messagesSent = 0;
String host = "127.0.0.1";
String port = "11005";
WSclient[] clientArr = new WSclient[clients];
for (int i = 0; i < clientArr.Length; i++)
{
clientArr[i] = new WSclient(host, port);
}
Random random = new Random();
var sw = Stopwatch.StartNew();
for (int i = 0; i < messages; i++)
{
clientArr[i % clients].Send("Message " + i);
messagesSent++;
}
sw.Stop();
Console.WriteLine("Clients " + clients);
Console.WriteLine("Messages to Send" + messages);
Console.WriteLine("Messages Sent " + messagesSent);
Console.WriteLine("Time " + sw.Elapsed.TotalSeconds);
Console.WriteLine("Messages/s: " + messages / sw.Elapsed.TotalSeconds);
Console.ReadLine();
for (int i = 0; i < clientArr.Length; i++)
{
clientArr[i].Disconnect();
}
Console.ReadLine();
}
但是,服务器接收到的消息较少(即使消息数量很少,例如100条).有时有时会收到多封邮件作为一条邮件,例如:
However the server is receiving less messages (even with a small number e.g. 100). Or sometimes multiple messages are received as a single message e.g.:
Message1 = abc Message2 = def
Message1 = abc Message2 = def
接收为= abcdef
Received As = abcdef
I am trying to more or less replicate the example shown here . At the moment both the server and the client are running locally. Any ideas on what the problem is or on how to improve the test method?
推荐答案
在github项目上有两个听起来很相似的未解决问题:
There are two open issues on the github project that sound similar:
- Server drops inbound messages and receives corrupted input
- JSON messages truncated
其中一位评论者表示, Fleck
One of the commenters reported better luck with Fleck
这篇关于Web套接字消息未全部收到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!