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?
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).
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).
Usually, websocket client response is not slow. Why your one is slow, please check the await method Don't put await method in while True loop
If you put await, the response time is also too long and too slow. You can test and I suggest to test also remove await method and write sample codes and I will see how fast the websocket client. haha
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With