PostgreSQL UNIX domain sockets against TCP sockets

Interestingly, if UNIX domain socket connections to postgresql are faster than tcp connections from localhost with high concurrency, and if so, how much?

+41
performance postgresql sockets tcp
Nov 02 '08 at 21:50
source share
5 answers

UNIX domain sockets should provide better performance than TCP sockets through the loopback interface (less data copying, fewer context switches), but I don’t know if PostgreSQL can demonstrate performance improvements.

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

+29
Nov 02 '08 at 22:21
source share

The main developer of Postgres is Bruce Momjian's blog about this topic . Momjian states: "Unix domain socket exchange is much faster." He measured the performance of the query network, indicating that the local domain socket was 33% faster than using the TCP / IP stack.

+45
Aug 24 2018-12-12T00: 00Z
source share

I believe that UNIX domain sockets in theory provide better bandwidth than TCP sockets on the loopback interface, but in practice the difference is probably not significant.

Data carried by UNIX sockets must not pass up and down the IP stack.

re: Alexander is the answer. AFAIK, you should not get more than one context switch or copy of the data in each direction (i.e., for each read() or write() ), so I think the difference will be careless. The IP stack does not need to copy a packet when moving between layers, but it has to manipulate internal data structures to add and remove higher level packet headers.

+5
Nov 02 '08 at 22:26
source share

afaik, unix domain socket (UDS) works as system channels, and it sends ONLY data, and does not send checksum and other additional information, and does not use a three-way handshake as TCP sockets ...

ps: maybe UDS will be faster

+4
Nov 02 '08 at 22:24
source share

TCP sockets on the local host are usually implemented using UNIX domain sockets, so the answer on most systems does not matter to anyone. However, this is by no means the standard - that is how it is usually done, so you should not depend on it.

-3
Nov 02 '08 at 22:07
source share



All Articles