Search code examples
c#.netmultithreadingnotificationsappdomain

Highest Performance for Cross AppDomain Signaling


My performance sensitive application uses MemoryMappedFiles for pushing bulk data between many AppDomains. I need the fastest mechanism to signal a receiving AD that there is new data to be read.

The design looks like this:

AD 1: Writer to MMF, when data is written it should notify the reader ADs

AD 2,3,N..: Reader of MMF

The readers do not need to know how much data is written because each message written will start with a non zero int and it will read until zero, don't worry about partially written messages.

(I think) Traditionally, within a single AD, Monitor.Wait/Pulse could be used for this, I do not think it works across AppDomains.

A MarshalByRefObject remoting method or event can also be used but I would like something faster. (I benchmark 1,000,000 MarshalByRefObject calls/sec on my machine, not bad but I want more)

A named EventWaitHandle is about twice as fast from initial measurements.

Is there anything faster?

Note: The receiving ADs do not need to get every signal as long as the last signal is not dropped.


Solution

  • The named EventWaitHandle is the way to go for a one way signal (For lowest latency). From my measurements 2x faster than a cross-appdomain method call. The method call performance is very impressive in the latest versions of the CLR to date (4) and should make the most sense for the large majority of cases since it's possible to pass some information int he method call (in my case, how much data to read)

    If it's OK to continuously burn a thread on the receiving end, and performance is that critical, a tight loop may be faster.

    I hope Microsoft continues to improve the cross appdomain functionality as it can really help with application reliability and plugin-ins.