简体   繁体   English

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

[英]What's the fastest IPC method for a .NET Program?

Named Pipes ? 命名管道? XML-RPC ? XML-RPC? Standard Input-Output ? 标准输入输出? Web Services ? 网页服务 ?

I would not use unsafe stuff like Shared Memory and similar 我不会使用像共享内存等类似的不安全的东西

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. 命名管道通信不会一直沿着网络堆栈(因为它只适用于同一台计算机上的通信)所以它总是会更快。

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. 由于XML中的大量开销,任何基于XML的通信协议(例如,Web服务)通常都会变慢。

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. 如果我是你,我会 Stevens和Rago 的Unix环境 (APUE)中购买/借用高级编程的副本,并阅读关于IPC的第15章和第16章。 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. 如果您真的想了解* nix(其中很多适用于任何POSIX系统)是如何工作到内核级别的,那么这本书是一本精彩的书。

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 本地机器IPC

Network IPC/Internet Sockets 网络IPC / Internet套接字

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. 在这两个级别,您将不得不考虑如何对传输的数据进行编码/解码,并在内存使用和CPU利用率之间进行权衡。

At the Network level, you will have to consider what layers of protcols you are going to run on top of. 在网络级别,您将不得不考虑将要运行的protcols层。 Most commonly, at the bottom of the application layer you will be choosing between TCP/IP or UDP. 最常见的是,在应用程序层的底部,您将选择TCP / IP或UDP。 TCP has a lot more overhead as it is does error correction, checksumming and lots of other stuff. TCP有更多的开销,因为它有纠错,校验和和许多其他东西。 if you need in order delivery of messages you need to use TCP as opposed to UDP. 如果您需要按顺序传递消息,则需要使用TCP而不是UDP。

On top of these are other protocols like HTTP, SOAP (on top of HTTP or another protocol like FTP/SMTP etc.). 除此之外还有其他协议,如HTTP,SOAP(在HTTP之上或其他协议,如FTP / SMTP等)。 A binary protocol is going to be more efficient as long as you are network bound rather than CPU bound. 只要您是网络绑定而不是CPU绑定,二进制协议将更有效。 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. 如果在MS.Net平台上使用SOAP,那么消息的二进制编码将在网络上更快,但可能会占用更多CPU。

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. 学习延迟是什么以及如何处理缓冲是能够决定你总是被迫使用IPC的权衡的关键。 I'd recommend the APUE book above if you really want to know what is going on under the hood... 如果你真的想知道引擎盖下发生了什么,我会推荐上面的APUE书......

Windows Messaging is one of the fastest ways for IPC, after-all Windows is built on them. Windows Messaging是IPC的最快方式之一,后面的所有Windows都是基于它构建的。

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. 可以将WM_COPYDATA与IPInvoke调用一起使用,以在两个基于表单的.Net应用程序之间交换数据,并且我有一个开源库来完成这项工作。 I've bench marked around 1771 msg/sec on a fairly hot laptop. 我在一台相当热的笔记本电脑上以1771 msg /秒的速度进行了标记。

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

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). 我不知道为什么你不会使用共享内存,但它在同一台机器上从C#到C#应用程序的速度非常快 ,并且非常可靠(与TCP套接字不同)。 spazzarama/SharedMemory is a fantastic C# lib that supports shared arrays and buffers with a simple high level API. spazzarama / SharedMemory是一个出色的C#lib,它支持使用简单的高级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! 价值神奇地出现在另一边!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么是.Net程序索引用户计算机上所有图像的最快方法? - What is fastest way for a .Net program to index all images on a user's computer? 最快的方法是什么? - What would be the fastest method? 检查SQL服务器可用性的最快方法是什么? - What's the fastest method to check SQL server availability? 什么是将一堆位图转储到PDF的最快的.Net PDF库? - What's the fastest .Net PDF library to dump a bunch of bitmaps to PDF? 使用.Net绘制解析树的最简单,最快捷的方法是什么? - What's the simplest and fastest way to draw a parse tree using .Net? 在 .NET 中有效计算一个向量与多个向量的余弦相似度的最快方法是什么? - What is the fastest method of efficiently calculating cosine similarity of one vector to many in .NET? 在 .NET 6 中访问配置的最佳方法是什么? - What's the best method to access configuration in .NET 6? 在.Net 2.0应用程序中缓存数据库表。 最快的访问方式是什么? - Cache a DB table in a .Net 2.0 app. What's the fastest way of accessing it? 使用LibTiff.Net从tif图像中获取tiff标签计数的最佳/最快方法是什么? - What's the best/fastest way to get the count of tiff tags from a tif image with LibTiff.Net? 在.NET中搜索数组以匹配颜色的最快方法 - Fastest method to search an array for matching color in .NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM