1

I'm using TCP sockets to do local IPC between applications running on the same machine.

The data that is exchanged in this IPC is very simple: The client sends a 4-byte request, the server sends a 128kB response, this happens basically in a tight loop.

Now if I open the connection to 127.0.0.1 or ::1, I get the expected shortcut through loopback, as described in this question and the delay is very low.

If I open the connection to 192.168.0.2 (the local v4 address of the machine), the same thing happens. The network stack seems smart enough to detect that it's the same machine and the latency is very low.

Now if I open the connection to any of the global v6 addresses of my machine (doesn't matter if temporary or not), the latency increases immensely if I'm on OSX (10.11.3), however not on Linux. It seems like Linux is smart enough to detect it could be using loopback and speeds things up, while OSX can't do that with the v6 address.

To summarise:

  • 127.0.0.1: fast everywhere
  • local v4 address: fast everywhere
  • local v6 address: fast on Linux, slow on OSX

Is this a known defect of OSX, or is Linux doing something it shouldn't be doing?

EDIT: It does not make a difference whether I use the TCP_NODELAY option or not.

Philipp
  • 957
  • 1
  • 6
  • 20
  • apple.stackexchange.com would probably be a better place to ask about OS X bugs. Although this sounds like just a lack of an optimization, not a true bug. – Barmar Feb 09 '16 at 01:06
  • In El Capitan, I've found worse than that -- sending non-trivial amounts of information via local IPv6 addresses would cause my network devices to go offline or even cause a kernel panic(!). So it appears to me that MacOS/X's data path to local IPv6 addresses is indeed buggy. (I reported the bug to apple and they closed it as a duplicate of case 24097981, FWIW. In my code I work around the problem by checking to see if an IPv6 address is the address of one of my local network interfaces, and if so, I use ::1 instead) – Jeremy Friesner Feb 09 '16 at 04:05
  • Btw if you're seeing the same problem I was seeing, another aspect of it will be obvious if you keep MacOS's Network preferences pane open while reproducing the problem; you may see the little colored circle to the left of the network device entry (in the list view at the left hand side of the prefs pane) turn red for a second or two, then go back to green again, and repeat. – Jeremy Friesner Feb 09 '16 at 04:12

0 Answers0