Is it better to reuse connections or update them to send data frequently?

I have a TCP server application that listens for connections from clients that send heartbeat packets often at short intervals, about 20 seconds. There are several such clients, not more than 1000.

It was previously implemented (and not by me) such that for each beat a new TCP connection is used, then it closes.

It seems to me that it would be better to keep the connection open and reuse it for communication, but I'm not sure. Is re-establishing connections a waste of time and bandwidth and maintaining several hundred open connections (in the case of a server) is not a problem, or, conversely, is it a big waste of resources not to close them?

+2
source share
1 answer

It depends on the amount of memory you have, on the connection timeout and heart rate, which are the best options:

  • Each TCP connection takes 1xRTT time to configure, so creating a new connection each time is expensive in terms of time, but not resources.
  • Each open TCP connection has a state that must be saved on the system, which means that it is taking up memory resources.
+2
source

All Articles