【问题标题】:Why to use local pipes instead of sockets for programs communication inside one computer?为什么在一台计算机内使用本地管道而不是套接字进行程序通信?
【发布时间】:2011-03-04 12:52:33
【问题描述】:

为什么在一台计算机内使用本地管道而不是套接字进行程序通信?有任何一个 FRESH 统计数据,关于谁更快、多少 nm,哪个更sequre 或更少?

我发现了一个谨慎的古老、奇怪和可怕的...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 用户)

【问题讨论】:

  • 命名管道不适用于大块数据。如果你发送的消息最多只有几十个字节,管道的性能是一样的

标签: sockets statistics ipc named-pipes


【解决方案1】:

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

至于一个比另一个快多少,这取决于您的硬件和操作系统。

【讨论】:

  • 不过,命名管道可用于应用程序之间的网络通信。
  • Windows 上的网络管道很糟糕,它们使用 SMB 协议,速度比套接字慢。
猜你喜欢
  • 2012-07-06
  • 2010-12-27
  • 1970-01-01
  • 2011-03-30
  • 2017-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多