Skip to main content

How to avoid losing the messages or delay on the WebSocket?

The problem of lost messages in the WebSocket stream can be identified:

1. directly on the stream by the gaps in the sequence number

Possible causes are limited and are related to the:

1. Bandwidth bottleneck
2. Lack of the separation between the receiving thread and parsing, processing operations
3. No CPU affinity on the receiving thread
4. CPU bottleneck on the receiving thread
5. Infrequent collection of the data from the TCP stack
6. Heap allocation per message and Garbage Collector pressure

If your client is unable to receive messages fast enough because of the issues listed above then these things will happen:

1. Your client TCP stack will be full, and TCP window will be closed to inform us that you can't receive more data and we should not send to you
2. Our TCP stack queue will be full because we couldn't send you more data
3. We will internally create a limited queue of the messages to deliver when the channel is available again (this could cause the delay on the real-time data before the gaps will appear)
4. We will start dropping the messages

More information is available by googling "TCP Flow Control".