Take the 2-minute tour ×

Working on an Android and iOS based application which require communication with a server running in the same device. Currently using TCP loopback connection for communicating with App and Server (App written in user layer, server written in C++ using Android NDK)

I was wondering if replacing inter communcation with Unix Domain socket would improve the performance?

Or in-general is there any evidence/theory that proves that Unix Domain socket would give better performance then TCP loopback connection?

Many Thanks in advance.

share|improve this question
Remember that local sockets (UNIX domain sockets) need a file in the filesystem. Using the TCP loopback address keeps it all in memory. And if you have to use remote TCP sockets, it might be easier to integrate another TCP socket instead of fiddling with a new socket and address family. –  Joachim Pileborg Feb 20 '13 at 6:56
i just found a link bhavin.directi.com/unix-domain-sockets-vs-tcp-sockets –  PowerPC Feb 20 '13 at 7:00
@JoachimPileborg When developing only for Linux (Android) there is the option to use abstract UNIX domain socket addreses, which do not need a file in the filesystem. –  thuovila Feb 20 '13 at 7:50
refer stackoverflow.com/questions/14643571/… for android connection. –  PowerPC Feb 20 '13 at 8:32

3 Answers 3

up vote 22 down vote accepted

Yes, local interprocess communication by unix domain sockets should be faster than communication by loopback localhost connections because you have less TCP overhead, see here and here.

share|improve this answer
the first link is citing the second link, which is from 2005 (old). and it only covers FreeBSD –  Janus Troelsen Jan 31 at 16:34
This answer is wrong, when tested loopback tcp on modern linux is as fast and sometimes faster than UDS. can provide benchmark if required –  easytiger Jun 18 at 13:11
I require that you provide benchmark. –  ggPeti Jul 4 at 16:03
This answer is absolutely correct. Loopback interface is still TCP, meaning that you still have the overhead of TCP (congestion control, flow control, stream management (IP packet ordering, retransmission, etc) ). Unix domain sockets do not do any of the above because it was designed from the ground up to be ran locally, meaning no congestion issues, no speed differences between server/client requiring flow control, no dropped packets, etc. Google this if in doubt, not a new thing. –  JSON Oct 17 at 20:45
Also note that even local TCP requires every bit to be ACKed. The latency of these acks can be more costly in time than TCP processing. –  JSON Oct 17 at 20:52

Redis benchmark shows unix domain socket can be significant faster than TCP loopback.


However, this difference only matters when throughput is high.

share|improve this answer

Unix domain sockets are often twice as fast as a TCP socket when both peers are on the same host. The Unix domain protocols are not an actual protocol suite, but a way of performing client/server communication on a single host using the same API that is used for clients and servers on different hosts. The Unix domain protocols are an alternative to the interprocess communication (IPC) methods.

share|improve this answer

Your Answer


