PostgreSQL UNIX域套接字与TCP套接字

时间:2022-09-11 22:29:57

I wonder if the UNIX domain socket connections with postgresql are faster then tcp connections from localhost in high concurrency rate and if it does, by how much?

我想知道与postgresql的UNIX域套接字连接是否比高并发率的本地主机的tcp连接更快,如果有的话,是多少呢?

5 个解决方案

#1


30  

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

UNIX域套接字应该比TCP套接字提供比回送接口更好的性能(减少数据复制,减少上下文切换),但我不知道PostgreSQL是否可以证明性能提升。

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

我在FreeBSD邮件列表上找到了一个小的比较:http://lists.freebsd.org/pipermail/freebsd-performance/2005-February/001143.html。

#2


46  

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

Postgres核心开发人员Bruce Momjian在博客上发表了关于这个话题的博文。 Momjian表示,“Unix域套接字通信的速度要快得多。”他测量了查询网络性能,显示本地域套接字比使用TCP / IP堆栈快33%。

#3


5  

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

我认为UNIX域套接字在理论上比环回接口上的TCP套接字提供更好的吞吐量,但实际上差异可能是微不足道的。

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

通过UNIX域套接字传输的数据不必在IP堆栈层中上下移动。

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

回复:亚历山大的回答。 AFAIK你不应该在每个方向上获得多于一个的上下文切换或数据拷贝(即对于每个read()或write()),因此我认为差异将是可忽略的。 IP堆栈在层之间移动时不需要复制数据包,但它必须操纵内部数据结构以添加和删除更高层的数据包标头。

#4


4  

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

afaik,unix域套接字(UDS)像系统管道一样工作,它只发送数据,不发送校验和和其他附加信息,不使用三次握手作为TCP套接字......

ps: maybe UDS will be more faster

ps:也许UDS会更快

#5


-3  

TCP sockets on localhost are usually implemented using UNIX domain sockets, so the answer on most systems is neglijable to none. However, this is not standard in any way -- it is just how usually it is done, therefore you should not depend on this.

localhost上的TCP套接字通常使用UNIX域套接字实现,因此大多数系统上的答案都是不可忽略的。但是,这在任何方面都不是标准的 - 它只是通常的方式,因此你不应该依赖于此。

#1


30  

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

UNIX域套接字应该比TCP套接字提供比回送接口更好的性能(减少数据复制,减少上下文切换),但我不知道PostgreSQL是否可以证明性能提升。

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

我在FreeBSD邮件列表上找到了一个小的比较:http://lists.freebsd.org/pipermail/freebsd-performance/2005-February/001143.html。

#2


46  

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

Postgres核心开发人员Bruce Momjian在博客上发表了关于这个话题的博文。 Momjian表示,“Unix域套接字通信的速度要快得多。”他测量了查询网络性能,显示本地域套接字比使用TCP / IP堆栈快33%。

#3


5  

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

我认为UNIX域套接字在理论上比环回接口上的TCP套接字提供更好的吞吐量,但实际上差异可能是微不足道的。

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

通过UNIX域套接字传输的数据不必在IP堆栈层中上下移动。

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

回复:亚历山大的回答。 AFAIK你不应该在每个方向上获得多于一个的上下文切换或数据拷贝(即对于每个read()或write()),因此我认为差异将是可忽略的。 IP堆栈在层之间移动时不需要复制数据包,但它必须操纵内部数据结构以添加和删除更高层的数据包标头。

#4


4  

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

afaik,unix域套接字(UDS)像系统管道一样工作,它只发送数据,不发送校验和和其他附加信息,不使用三次握手作为TCP套接字......

ps: maybe UDS will be more faster

ps:也许UDS会更快

#5


-3  

TCP sockets on localhost are usually implemented using UNIX domain sockets, so the answer on most systems is neglijable to none. However, this is not standard in any way -- it is just how usually it is done, therefore you should not depend on this.

localhost上的TCP套接字通常使用UNIX域套接字实现,因此大多数系统上的答案都是不可忽略的。但是,这在任何方面都不是标准的 - 它只是通常的方式,因此你不应该依赖于此。