I am benchmarking different parallelization approaches in .NET and found that CCR is embarassingly slow. For a massively parallelizable task, CCR takes 5 times what it would take to do serially! Am I doing something wrong or is that just the way it is?
Each Port.Post() and the subsequent Receive() takes a whopping 2 to 8 milliseconds. Why?
The setup: a method, long ComputationalTask(long arg) takes some time to do a computation. This is repeated 100,000 times with args from 0 to 99,999. ComputationTask has no side effects, so it is massively parallelizable.
100k serial ComputationalTask() calls in a single thread take 44 seconds. Therefore, on a quad core CPU parallelizing to 4 threads should take 11 seconds, overhead not included.
BeginInvoke'ing each computation and waiting for the result takes 14 seconds. Parallel.For() and PLINQ take a litle over 12 seconds each.
CCR, however, takes a whopping 5 minutes (296 seconds) to do the same task! Why?
The code is here: http://monoport.com/39549. The test was performed on Core 2 Quad Q8200, 2.33Ghz, 4GB memory, .NET 3.5 SP1, Windows Vista.
Hi, Port.Post takes about 300 nano secs, and task scheduling overhead is in the order of the OS thrad switch time (so again less than 1 micro sec). Last time we checked are on par or faster than any alternative you tried, for the same type of computation.
One wierd thing i see in your code is that your CCR example is overly complicated compared to the other comparisons. You are doing 1) one port post to a persisted receiver 2) then you do another post post to an iterator, within that receiver! 3) then you loop in an iterator 4) then you call the computational task!
All you need to do, for apples to apples comparison:
1) post N times to a persisted receiver 2) Have the receiver execute the computational task! When some counter reaches zero, print our result
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.