[ACCEPTED]-PostgreSQL UNIX domain sockets vs TCP sockets-sockets

Accepted answer
Score: 61

Postgres core developer Bruce Momjian has 5 blogged about this topic. Momjian states, "Unix-domain socket 4 communication is measurably faster." He 3 measured query network performance showing 2 that the local domain socket was 33% faster 1 than using the TCP/IP stack.

Score: 41

UNIX domain sockets should offer better 6 performance than TCP sockets over loopback 5 interface (less copying of data, fewer context 4 switches), but I don't know whether the 3 performance increase can be demonstrated 2 with PostgreSQL.

I found a small comparison 1 on the FreeBSD mailinglist: http://lists.freebsd.org/pipermail/freebsd-performance/2005-February/001143.html.

Score: 8

I believe that UNIX domain sockets in theory give 13 better throughput than TCP sockets on the 12 loopback interface, but in practice the 11 difference is probably negligible.

Data carried 10 over UNIX domain sockets don't have to go 9 up and down through the IP stack layers.

re: Alexander's 8 answer. AFAIK you shouldn't get any more 7 than one context switch or data copy in 6 each direction (i.e. for each read() or write()), hence 5 why I believe the difference will be negligble. The 4 IP stack doesn't need to copy the packet 3 as it moves between layers, but it does 2 have to manipulate internal data structures 1 to add and remove higher-layer packet headers.

Score: 6

afaik, unix domain socket (UDS) work like 4 system pipes and it send ONLY data, not 3 send checksum and other additional info, not 2 use three-way handshake as TCP sockets...

ps: maybe 1 UDS will be more faster

More Related questions