3

I am measuring the latency of a TCP/IP connection on windows over the loopback interface and getting about 4ms for the time from a message is sent to a response is received.

For RPC purposes there is a TCF layer on top of TCP/IP. The messages sent and received contain only a single character as payload in addition to the TCF framing.

The "server" which handles the commands are implemented in C++ using boost asio. The "client" sending commands is a Python script that uses the Python TCF reference implementation.

I have tried setting the socket options to TCP_NODELAY to disable the Nagle algorithm and experimented with various buffersizes for the socket, but the roundtrip time remains at about 4ms. I was expecting it to be quite a bit lower.

Profiling on the C++ side shows that it spends about 50% of it's execution time waiting for commands, so the next step will be to try and replace the python script with a C++ implementation, but it would be nice to know what one can expect for the roundtrip time on the loopback interface.

This SO, question:
Linux Loopback performance with TCP_NODELAY enabled is related but did not quite answer my question.

Community
  • 1
  • 1
Torleif
  • 2,334
  • 3
  • 27
  • 28
  • 3
    If the C++ side is spending about half its time waiting, then presumably it's spending about half it's time not waiting. If you assume the same for the other side, that leaves an estimated latency of zero. All time is accounted for. Half the time is consumed by the C++ code doing work. Half the time is consumed by the Python code doing work. That leaves no time neither side is working, which is what would happen during any TCP/IP latency. (The side sending would be waiting for a reply and the side receiving would be waiting to receive. Both sides would be waiting.) – David Schwartz Jun 30 '12 at 20:57
  • +1 for 'Spock' answer by @DavidSchwartz – Martin James Jul 01 '12 at 13:28
  • @DavidSchwarz: +1 I didn't think of that :-) Thanks. Still, I would very much like to know what a typical TCP/IP roundtrip time should be. – Torleif Jul 01 '12 at 15:06
  • After implementing the "client" in C++, the latency of a command/response pair dropped to 170µs. Replacing calls to json_spirit with handcrafted jsonification of strings took it down to about 150µs. – Torleif Aug 02 '12 at 12:44

1 Answers1

6

You can establish a lower bound on the latency with ping localhost. The number it reports is one packet sent, one received.

If your TCP message is sent on an existing connection, you might get nearly that latency.

If your measured time included the TCP connection setup, you might get 10x that latency.

Robᵩ
  • 163,533
  • 20
  • 239
  • 308