There is a C# function A(arg1, arg2)
which needs to be called lots of times. To do this fastest, I am using parallel programming.
Take the example of the fo
You have determined that the code in A
is the problem.
There is one very common problem: Garbage collection. Configure your application in app.config
to use the concurrent server GC. The Workstation GC tends to serialize execution. The effect is severe.
If this is not the problem pause the debugger a few times and look at the Debug -> Parallel Stacks
window. There, you can see what your threads are doing. Look for common resources and contention. For example if you find many thread waiting for a lock that's your problem.
Another nice debugging technique is commenting out code. Once the scalability limit disappears you know what code caused it.