Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding .NET Multithreading Bottlenecks

Greetings.

I have a .NET application running a bunch of simulations in parallel. It's doing a parameter sweep, so each parameter has its own Parallel.Foreach loop. I normally set the max parallelism to one in all but one of loops, to keep memory requirements down, since each parameter can take more values than I have cores available (4).

The application is totally CPU bound, and only does I/O at the end, to write out results. I only have one lock around the data structure capturing the results, but that is accessed very seldom (once every few seconds). No matter how far I push the parallelism (by controlling the max parallelism on the loops) I always get an average CPU usage of about 50% (~ 2 cores).

I'd like to find out what prevents a higher CPU usage. My guesses are: 1) some call to .NET libraries that are synchronised, thus serialising the calls. 2) The GC stepping in to clean up resources (there's a lot garbage being produced by the application).

Any ideas how to go about the investigation?

Thanks a lot.

like image 448
Mau Avatar asked Jul 24 '26 11:07

Mau


1 Answers

I think debugging of multithreading issues always requires knowledge about code details, so there is not general recipe. But I think the GC is a very good first guess. Have you already tried this one:

http://msdn.microsoft.com/en-us/library/ms229357.aspx

I had a similar problem and using gcServer has allowed it to push the CPUs (8 cores) to it's limits.

like image 112
Achim Avatar answered Jul 26 '26 02:07

Achim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!