Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 357
Joe Avatar asked Mar 28 '11 22:03

Joe


2 Answers

A thread context switch costs between 2000 and 10,000 machine cycles on Windows. If you want more than a million per second then you are going to have to solve the Great Silicon Speed Bottleneck. You are already on the very low end of the overhead.

Focus on switching less often and collecting more data in one whack. Nothing needs to switch at a microsecond.

like image 53
Hans Passant Avatar answered Nov 10 '22 11:11

Hans Passant


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.

like image 42
Joe Avatar answered Nov 10 '22 09:11

Joe