[英]Flooding WebSocket
Am new to websocket and i implemented websocket on web application which the server-side is written in java and client-side is javascript. Websocket是一个新手,我在Web应用程序上实现了Websocket,服务器端是用Java编写的,而客户端是javascript。 Server send notifications to client via websocket. 服务器通过websocket向客户端发送通知。 I wonder what would happened if client won't be fast enough to handle incoming messages as fast as server is sending them. 我不知道如果客户端不能像服务器发送邮件那样快地处理传入消息,将会发生什么情况。 For example it is possible that server will be sending about 200 text messages per second, client is slow and is handling 100 messages per second. 例如,服务器每秒可能发送大约200条文本消息,客户端很慢,每秒处理100条消息。 I believe that browser queue incoming messages before it's processed but not sure. 我认为浏览器会在处理传入的消息之前对其进行排队,但不确定。 I what to also know how to check this buffer size and it's limit, and what would happen if buffer limit is reached. 我还知道如何检查此缓冲区大小及其限制,以及达到缓冲区限制后会发生什么情况。 Any idea on how i can simulate this kind of situation, i tried: 关于如何模拟这种情况的任何想法,我都尝试过:
webSocket.onmessage = function (message) {
var bool = true;
var datenexexec = Date.now() + 1000;
while(bool) {
if(Date.now() > datenexexec){
bool = false;
}
}
}
but this causes the browser to only hang and later crash. 但这导致浏览器仅挂起,随后崩溃。 Thanks for help. 感谢帮助。
For sending data more rapidly than the client can read it, here's what will eventually happen. 为了更快地发送数据,而不是让客户端读取数据,最终将发生以下情况。
TCP is a reliable protocol so it will just buffer and transmit later until the buffer is full. TCP是可靠的协议,因此它将仅缓冲并稍后传输,直到缓冲已满。 It shouldn't lose packets by itself (unless the connection drops), but when buffers are full, it will give you an error that it can't send any more because the buffer is full. 它不应自行丢失数据包(除非连接断开),但是当缓冲区已满时,它将给您一个错误,因为缓冲区已满,它不能再发送了。
As for the client-side code you tried, you can't busy/wait in Javascript for very long. 至于您尝试的客户端代码,您不能在Java语言中等待很长时间。 That kills the event loop and eventually brings down the script engine. 这会杀死事件循环,并最终导致脚本引擎崩溃。
The only way for you to simulate this is to try to actually send more packets than the client can process. 模拟此情况的唯一方法是尝试实际发送比客户端可以处理的数据包更多的数据包。 You can code a "slow" client that takes maybe 250ms to process each packet in a short busy/wait loop and a "fast" server that sends a flood of packets and you should be able to simulate it. 您可以编写一个“慢”客户端程序,该客户端程序可能需要250毫秒来处理短暂的繁忙/等待循环中的每个数据包,还可以编写一个“快速”服务器来发送大量数据包,您应该能够对其进行仿真。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.