Monday, September 3, 2007

.NET Application runs faster as multi processed than multi threaded

I have simulation that does a lot of number crunching. I wanted to make it faster utilizing the CPU (I have a quad CPU). I tired to run the same algorithm it two ways:

  1. One process with several threads.
  2. Several process with one thread in each.

Each thread ran the same algorithm and internally spawn other threads.

I found out that the option 2 was faster than option 1. Looking into it I concluded that the first option spends too much time in the GC. Every time the GC runs it suspends all the threads of the process causing all the algorithms that run on the same process to stop.

By looking at the performance monitor the first option spends ~50% in GC, while the second option spends ~25% in GC.

Also checking the total time it took to run. The difference was higher as the number of algorithms run concurrently was higher.

 

Ami

1 comment:

F.D.Castel said...

Hi Ami!

Could you publish the code you used for this test? Do you tried it in another configurations? (single core, dual core, more memory, less memory, etc.)

It could give different results.

Best regards,

F.D.Castel