C#.NET MMF: Is implementation of proprietary communication over Memory Mapped file just reinvention of Named Pipes?

StackOverflow https://stackoverflow.com/questions/18822508

Question

I need to implement very fast, low latency, high throughput inter-process (or inter-appdomains) communication on a single machine.

Messages will typically flow every few milliseconds (but during few minutes peeks there can be even up to 3-5 messages per millisecond), with each message beeing about just under 1KB large and target roundtrip latency is max 1ms (by roundtrip I mean delivery of a message and then somehow calling back to producer to announce if consumer wants to 'claim' the message).

I did some research and it seems that Memory mapped files is the fastest available possibility, however I would need to proprietary implement the whole communication stack around it (allocation and management of shared memory, copying messages into it and from it and signaling to consumers that new message is ready to be consumed). I came across the picture showing architecture of IPC methods on Windows (http://blogs.msdn.com/b/salvapatuel/archive/2009/06/08/working-with-memory-mapped-files-in-net-4.aspx) and it seems that those methods already uses MMF. So by what I described - wouldn't I actually reinvent the wheel by re-implementing what Named Pipes already does. Or can I actually achieve significantly faster protocol than what named pipes can offer?

Edit1: Adding the frgotten link to picture showing that Named Pipes build on top of MMF (http://blogs.msdn.com/b/salvapatuel/archive/2009/06/08/working-with-memory-mapped-files-in-net-4.aspx)

Was it helpful?

Solution

Yes, a pipe is an abstraction on top of shared memory that lives in the kernel memory pool. A memory mapped file sits way on the bottom and gives you raw access to shared memory without anything to help you get it right, it is up to you to arbitrate access to the memory and signal changes.

The message rate you are quoting is not close to giving a pipe a hard time to keep up. Typical overhead is roughly 1 microsecond constant OS overhead plus the time needed to copy the message, set by the bandwidth of the memory bus. At least 5 gigabytes per second on the lowliest consumer PC with DDR2 RAM. A Socket with local loopback has the exact same overhead. So does an MMF in a managed program, copying data is rather inevitable unless you use pointers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top