0

I have a requirement in which server needs to interact with 2 clients, one residing on local machine and one on remote.

So, initially I was thinking of creating a socket using AF_UNIX for communication with local client (since its faster than AF_INET), and AF_INET in case of communication with remote, and polling between them.

But in case of local client, channel will only be created in the beginning which will exist permanently till the server is running, i.e. single accept, followed by multiple read/writes.

So, can I replace this AF_UNIX with AF_INET, since the connection establishment will be done only once? Where does performance hits in case of AF_INET? Is it in three-way handshake or somewhere else as well?

garima721
  • 323
  • 3
  • 14
  • On a pure throughput test where I was trying to use the largest writes and reads to shove as much data possible down the pipe I got performance numbers that were comparable. AF_UNIX had a slight edge, but nothing major. And AF_UNIX consistently transferred around 4 times as much data per system call. AF_UNIX performance was also a lot more variable, and I think was much more sensitive to the scheduler. kernel-4.11 on a recent Dell XPS 13. – Omnifarious Aug 23 '17 at 22:18
  • I didn't test how fast it was to initiate the connection in the first place though. Just straight IO throughput. – Omnifarious Aug 23 '17 at 22:19

1 Answers1

3

Quote from Performance: TCP loopback connection vs Unix Domain Socket:

When the server and client benchmark programs run on the same box, both the TCP/IP loopback and unix domain sockets can be used. Depending on the platform, unix domain sockets can achieve around 50% more throughput than the TCP/IP loopback (on Linux for instance). The default behavior of redis-benchmark is to use the TCP/IP loopback.

However, make sure that the performance gain is worth the tradeoff of complicating the network stack of your application (by using various types of sockets depending on client location).

Community
  • 1
  • 1
mkf
  • 700
  • 3
  • 12