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.
Do you have significant locking within your application? If the threads are waiting for each other a lot, that could easily explain it.
Other than that (and the other answers given), it’s very hard to guess, really. A profiler is your friend…
EDIT: Okay, given the comments below, I think we’re onto something:
Is the COM method running in an STA by any chance? If so, it’ll only use one thread, serializing calls. I strongly suspect that’s the key to it. It’s similar to having a lock around that method call (not quite the same, admittedly).