.NET 程序最快的 IPC 方法是什么?

发布于 2024-08-17 11:22:07 字数 60 浏览 3 评论 0原文

命名管道? XML-RPC ?标准输入输出 ?网络服务?

我不会使用共享内存等不安全的东西

Named Pipes ? XML-RPC ? Standard Input-Output ? Web Services ?

I would not use unsafe stuff like Shared Memory and similar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

筑梦 2024-08-24 11:22:07

命名管道将是最快的方法,,但它仅适用于同一台计算机上的进程之间的通信。命名管道通信不会一直沿着网络堆栈进行(因为它仅适用于同一台计算机上的通信),因此它总是会更快。

匿名 管道 只能在本地计算机上使用。但是,命名管道可以遍历网络。

我遗漏了共享内存,因为您特别提到您不想走那条路。不过,共享内存甚至比命名管道还要快。

所以这取决于你是否只需要在同一台计算机或不同计算机上的进程之间进行通信。由于 XML 的巨大开销,任何基于 XML 的通信协议(例如 Web 服务)通常都会较慢。

Named pipes would be the fastest method, but it only works for communication between processes on the same computer. Named pipes communication doesn't go all the way down the network stack (because it only works for communication on the same computer) so it will always be faster.

Anonymous Pipes may only be used on the local machine. However, Named Pipes may traverse the network.

I left out Shared Memory since you specifically mentioned that you don't want to go that route. Shared Memory would be even faster than named pipes tho.

So it depends if you only need to communicate between processes on the same computer or different computers. Any XML-based communication protocol (eg. Web Services) will usually be slower due to the massive overhead in XML.

迎风吟唱 2024-08-24 11:22:07

我认为这个问题没有快速的答案。如果我是你,我会购买/借用一本Unix 环境中的高级编程 (APUE) by Stevens 和 Rago 并阅读 IPC 的第 15 章和第 16 章。如果您确实想了解 *nix(其中很多内容适用于任何 POSIX 系统)如何深入到内核级别,那么这是一本精彩的书。

如果你必须有一个快速的答案,我会说以下(没有投入大量的思考),按效率降序排列:

本地机器IPC

网络 IPC/Internet 套接字

在这两个级别,您都必须考虑如何对传输的数据进行编码/解码,并在内存使用和CPU 利用率。

在网络级别,您必须考虑要在哪些协议层上运行。最常见的是,在应用程序层的底部,您将在 TCP/IP 或 UDP 之间进行选择。 TCP 的开销要大得多,因为它要进行纠错、校验和以及许多其他工作。如果您需要按顺序传递消息,则需要使用 TCP 而不是 UDP。

在这些协议之上还有其他协议,例如 HTTP、SOAP(在 HTTP 或其他协议之上,例如 FTP/SMTP 等)。只要您受网络限制而不是 CPU 限制,二进制协议就会更有效。如果在 MS.Net 平台上使用 SOAP,则消息的二进制编码在网络上的速度会更快,但可能会占用更多的 CPU 资源。

我还可以继续说下去。这不是一个简单的问题。了解延迟在哪里以及如何处理缓冲是能够在 IPC 上做出权衡决策的关键。如果你真的想知道幕后发生了什么,我会推荐上面的 APUE 书......

i don't think there's a quick answer to this. if i was you, i would buy/borrow a copy of Advanced Programming in the Unix Environment (APUE) by Stevens and Rago and read Chapter 15 and 16 on IPC. It's a brilliant book if you really want to understand how *nix (a lot of it applies to any POSIX system) works down to the kernel level.

If you must have a quick answer, i would say the following (without putting a huge amount of thought into it), in descending order of efficiency:

Local Machine IPC

Network IPC/Internet Sockets

At both levels, you are going to have to think about how the data you transfer is encoded/decoded and trade off between memory usage and CPU utilization.

At the Network level, you will have to consider what layers of protcols you are going to run on top of. Most commonly, at the bottom of the application layer you will be choosing between TCP/IP or UDP. TCP has a lot more overhead as it is does error correction, checksumming and lots of other stuff. if you need in order delivery of messages you need to use TCP as opposed to UDP.

On top of these are other protocols like HTTP, SOAP (on top of HTTP or another protocol like FTP/SMTP etc.). A binary protocol is going to be more efficient as long as you are network bound rather than CPU bound. If using SOAP on the MS.Net platform, then binary encoding of the messages is going to be quicker across the network but may be more CPU intensive.

I could go on. it's not a simple question. Learning where the latencies are and how buffering is handled are key to being able to make decisions on the trade offs you are always forced to with IPC. I'd recommend the APUE book above if you really want to know what is going on under the hood...

甜扑 2024-08-24 11:22:07

Windows Messaging 是 IPC 最快的方法之一,毕竟 Windows 是基于它们构建的。

可以使用 WM_COPYDATA 和 IPInvoke 调用来在 2 个基于表单的 .Net 应用程序之间交换数据,并且我有一个开源库可以实现这一点。我在一台相当热的笔记本电脑上进行了基准测试,速度约为 1771 条消息/秒。

http://thecodeking.github.com/XDMessaging.Net

Windows Messaging is one of the fastest ways for IPC, after-all Windows is built on them.

It's possible to use WM_COPYDATA with IPInvoke calls to exchange data between 2 form based .Net applications, and I've got an open source library for doing exactly that. I've bench marked around 1771 msg/sec on a fairly hot laptop.

http://thecodeking.github.com/XDMessaging.Net

可遇━不可求 2024-08-24 11:22:07

我不知道为什么您不选择共享内存,但它在同一台计算机上从 C# 到 C# 应用程序非常非常快,而且非常可靠(与 TCP 套接字不同)。 spazzarama/SharedMemory 是一个出色的 C# 库,它通过简单的高级 API 支持共享数组和缓冲区。您只需使用公共内存文件名(在客户端/服务器端)初始化类,然后更新数组。价值观神奇地出现在另一边!

I don't know why you won't go with shared memory, but its very very fast from C# to C# apps on the same machine, and very reliable (unlike TCP sockets). spazzarama/SharedMemory is a fantastic C# lib that supports shared arrays and buffers with a simple high level API. You just initialize the class with a common memory file name (on client/server sides), and then update the array. Values magically appear on the other side!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文