2010-06-16 18 views
4

为什么要在一台计算机内使用本地管道代替套接字进行程序通信?是否有任何一项FRESH统计数据表明谁的速度更快,数量如何,哪种情况更少或更少?为什么在一台计算机内使用本地管道代替套接字进行程序通信?

我已经找到了警惕老奇怪和可怕的一个... http://home.iae.nl/users/mhx/pipes&socks.html

There is a noticeable difference in performance between sockets and named pipes. 
Benchmark 1: 20 Mbytes copied between two iForths on machine 1; 
Benchmark 2: 20 Mbytes copied from an iForth on machine 2 to an iForth on machine 1. 

Systems for sock test: Windows XP Pro, running on (1) an Intel PIV 3GHz/1GB and (2) an Intel Core 2 Duo 2.66 GHz/2GB. The PC's were networked using motherboard Realtek network adapters (100 Mbit/s). 
Systems for npipe test: Windows NT 4.0, running on (1) an Intel Pentium 166MHz/48MB and (2) an Intel Pentium 200MHz/48MB. The PC's were networked using cheap NE2000 clones (10 Mbit/s). 

benchmark | process A read | process B write 
===========+================+================ 
sock bm 1 | 72 MB/sec | 732 MB/sec 
sock bm 2 | 11.5 MB/sec | 2.857 GB/sec 
npipe bm 1 | 15 MB/sec | 15 MB/sec 
npipe bm 2 | 715 KB/sec | 715 KB/sec 

而且here是一些奇怪的信息(至少对我来说 - Windows用户)

+0

命名管道不适用于大块数据。如果您最多发送几十个字节的消息,则管道具有相同的性能 – Lothar 2013-01-03 21:40:37

回答

6

管道应始终快因为它们完全绕过主机操作系统上的网络堆栈。管道被认为是更安全的,因为他们不听来自不受信任的远程计算机的数据(尽管套接字也可以被配置为仅在环回适配器上进行监听,从而避免监听远程计算机)。命名管道比套接字更不灵活,因为它们不允许网络通信。无论哪种情况,安全性仍然与您编写代码的程度有关。可以编写一个基于管道的应用程序,它比基于套接字的应用程序更安全。

至于比另一个更快将取决于您的硬件和操作系统。

+1

尽管如此,命名管道可用于网络上应用程序之间的通信。 – 2010-06-16 23:15:33

+0

Windows上的网络管道很糟糕,他们使用SMB协议,这个协议大小比套接字慢。 – Lothar 2013-01-03 21:39:09

相关问题