当 websocket 客户端太慢时,websocket 将如何工作? [英] How will websocket works when websocket client is too slow?

查看:66
本文介绍了当 websocket 客户端太慢时,websocket 将如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有连接到远程服务器的 websocket 客户端.服务器每秒向我发送大量数据(每秒约 10 000 条短消息).我如何理解我的 websocket 客户端将有时间读取所有传入数据?或者服务器可以理解 ws-client 不会读取所有数据并且会断开连接?当 ws-client 太慢时,websocket 协议将如何工作?

I have websocket client that connects to remote server. Server sends me a lot of data per second (~10 000 short messages per second). How I can understand that my websocket client will have time to read all incoming data? Or maybe server can understand that ws-client don't read all data and will drop connection? How websocket protocol will works when ws-client is too slow?

推荐答案

底层的websocket传输是TCP,这个协调不同发送和接收速率的话题叫做流量控制(它是TCP层的一个特性),并且这个特定问题被称为慢消费者"(在通过 TCP 发送大量数据时很常见,例如金融市场数据).

The underlying websocket transport is TCP, and this topic of coordinating different rates of sending and receiving is called flow control (it is a feature of TCP layer), and this specific problem is known as "slow consumer" (and is common when sending out very high amounts of data over TCP, such as financial market data).

TCP 层允许在通信链路中的某些点进行缓冲,这样如果阅读器无法跟上服务器发送的字节,字节可以临时存储在这些缓冲区中(直到客户端能够处理它们).在读取器端和发送器端都可以有缓冲区,通常与套接字相关联.然而,这些通常是固定大小的.一旦这些缓冲区已满,服务器将在下一次尝试发送一些字节时面临选择:要么断开连接,要么等待(阻塞")直到缓冲区中有空间可以发送更多字节.

The TCP layer allows for buffering at certain points in the communication link, so that if the reader cannot keep up with the bytes the server is sending, bytes can be temporarily stored in these buffers (until the client is able to process them). There can be buffers both on the reader side and on the sender side, typically associated with the socket. However these are generally of fixed size. Once these buffers are full, the server will then face a choice on its next attempt to send some bytes: either drop the connection, or, wait ("block") until there is room in a buffer to send more bytes.

所以这确实是服务器的决定,我想它很可能会断开连接(否则风险是由于套接字缓冲区已满,服务器上会消耗越来越多的内存).

So really is a server decision, and I guess most likely it will drop the connection (otherwise risk is that more and more memory gets consumed on the server due to full socket buffers).

这篇关于当 websocket 客户端太慢时,websocket 将如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆