Alex Rivera | Logout

Why doesn't multithreading in C# reach 100% CPU?

Asked 2008-11-05T17:19:08.533
30

I'm working on a program that processes many requests, none of them reaching more than 50% of CPU (currently I'm working on a dual core). So I created a thread for each request, the whole process is faster. Processing 9 requests, a single thread lasts 02min08s, while with 3 threads working simultaneously the time decreased to 01min37s, but it keeps not using 100% CPU, only around 50%.

How could I allow my program to use full processors capability?

EDIT The application isn't IO or Memory bounded, they're at reasonable levels all the time.

I think it has something to do with the 'dual core' thing.

There is a locked method invocation that every request uses, but it is really fast, I don't think this is the problem.

The more cpu-costly part of my code is the call of a dll via COM (the same external method is called from all threads). This dll is also no Memory or IO-bounded, it is an AI recognition component, I'm doing an OCR recognition of paychecks, a paycheck for request.

EDIT2

It is very probable that the STA COM Method is my problem, I contacted the component owners in order to solve this problem.

Edit
Report

2 Answers

0

This isn't an answer really, but have you checked perfmon to see what resources it is using and have you run profilers on the code to see where it is spending time?

How have you determined that IO or other non CPU resources are not the bottleneck?

Can you give a brief description of what the threads are doing?

answered 2008-11-05T17:34:00.860
0

One more note, have you tried launching your code not from Visual Studio (regardless of release / debug settings) ?

answered 2008-11-06T10:57:23.110

Your Answer