PostgreSQL UNIX 域套接字与 TCP 套接字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/257433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PostgreSQL UNIX domain sockets vs TCP sockets
提问by user20955
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?
我想知道 UNIX 域套接字与 postgresql 的连接是否比来自 localhost 的高并发率的 tcp 连接更快,如果是,那么快多少?
采纳答案by Alexander
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。
回答by NoelProf
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%。
回答by Alnitak
I believe that UNIX domain sockets in theorygive 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 堆栈不需要复制数据包,但它必须操纵内部数据结构来添加和删除更高层的数据包标头。
回答by slav0nic
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会更快
回答by Terminus
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.
本地主机上的 TCP 套接字通常使用 UNIX 域套接字实现,因此大多数系统上的答案是可以忽略不计的。然而,这在任何方面都不是标准的——这只是它通常完成的方式,因此您不应该依赖于此。