Home:ALL Converter>TCP loopback connection vs Unix Domain Socket performance

TCP loopback connection vs Unix Domain Socket performance

Ask Time:2013-02-20T14:53:14         Author:Rohit

Json Formatter

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 communication 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?

Author:Rohit,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/14973942/tcp-loopback-connection-vs-unix-domain-socket-performance
0x4a6f4672 :

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.",
2013-04-11T14:59:13
Guillermo Lopez :

This benchmark: https://github.com/rigtorp/ipc-bench \nprovides latency and throughput tests for TCP sockets, Unix Domain Sockets (UDS), and PIPEs. \n\nHere you have the results on a single CPU 3.3GHz Linux machine :\n\nTCP average latency: 6 us\n\nUDS average latency: 2 us\n\nPIPE average latency: 2 us\n\nTCP average throughput: 0.253702 million msg/s\n\nUDS average throughput: 1.733874 million msg/s\n\nPIPE average throughput: 1.682796 million msg/s\n\n\n66% latency reduction and almost 7X more throughput explain why most performance-critical software has their own IPC custom protocol.",
2015-04-03T16:55:29
woodings :

Redis benchmark shows unix domain socket can be significant faster than TCP loopback.\n\n\n 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.\n\n\nHowever, this difference only matters when throughput is high.\n\n",
2014-12-04T19:03:56
peterDriscoll :

Unix domain sockets are often twice as fast as a TCP socket when both peers are on the same host. \nThe 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.",
2014-06-09T10:45:26
yy