Cola_Colin
Cola_Colin

Reputation: 485

Websockets & TCP: Sending few small packages with minimal delay

I am writing a client application to a websocket server.

I receive a lot of messages and occasionally (every 30 minutes or so) want to send a small block of data, less than 1kb.

I want to minimize the time it takes for this small block of data to be received, every ms counts.

The connection this works on is pretty much LAN-quality, ping to the server is 0.3ms. My client is written in C++. I do not control the server.

What can I do to minimize this latency? I guess TCP_NO_DELAY might be a good idea?

Upvotes: 0

Views: 245

Answers (1)

David Schwartz
David Schwartz

Reputation: 182763

No. TCP_NODELAY exists to permit protocols that were not designed to work with TCP to perform better when layered on top of TCP. It is not appropriate for applications designed to be layered on top of TCP and it will produce pathological behavior under poor conditions.

There are two things you need to do:

1) Do not send small chunks of data unless they are complete. That is, aggregate an entire query or request to send in a single go.

2) Include application-level acknowledgements into your protocol so that TCP ACKs can piggyback on them. That is, have the server send some kind of "okay" back to the client after each request is received, even if that is not strictly required by your application-level protocol.

Upvotes: 2

Related Questions