Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

90%+ CPU Usage...  :(

Hi there,

I have a small .NET app which crawls lots of documents all the time. It uses a maximum of 10 threads running parallel at any one time. Using multi-threading, there are no responsiveness issues. However, being busy doing stuff all the time, the application constantly consumes 80-90% CPU time according to task manager. I know task manager isn't the most "exact" profiler but it helps you get the idea---as would my laptop's fan while the app is running!

I think lowering the process's priority is not the best option for this (besides I tried and it didn't help). Other applications tend to be slower (particularly Windows Explorer) while it is running, and I'd like to prevent that. How do other processing-intensive applications (i.e. those that do more than maintain a windows message queue and send the occasional button click event to your code) handle this? When index server or Google Desktop search are indexing my computer, they don't seem to be as resource consuming. (Granted, they only get active when I appear to be "idle"...) But I also seem to remember applications such as WinHTTrack that don't necessarily slow the machine down when going about their business...

Any ideas greatly appreciated,

Thursday, May 19, 2005

"I think lowering the process's priority is not the best option for this"

Why? That's precisely what priority is for - so less important tasks cede when more important (such as responsive GUI apps) make demands on the processor.

Of course if you set the priority lower, it'll still use 100% when running (presuming it's not tied in asynchronous waits), but if another app demands some attention it'll get it, rather than having to fight with your app for it.

Dennis Forbes
Thursday, May 19, 2005

I've never understood the "OMyGosh! It's using X% of the processor!" complaint.

If it ain't a problem, and everything's still responsive, don't give it a second thought.

Back in my days with IBM, we had several mainframes cranking out about 115% during peak hours (things got queued up and had to wait). Big deal. The processing still got done. What's the problem?

Thursday, May 19, 2005

What's the problem? It's more a usability problem, I guess. "Average" users don't like it if everything all of a sudden responds extremely slowly.

Thanks for the replies, guys. Setting process priority to lowest did indeed the job. Another interesting approach was posted to the microsoft.public.dotnet.performance group, revolving around letting threads sleep for a bit. No point in my case since the stuff should still get done as soon as possible by the application.

Friday, May 20, 2005

Sleep(0), which is basically an empty yield, is a nice way to play nice (it harkens back to the days of cooperative multitasking), however the extra task switching, above and beyond what the task scheduler would have done, can add inefficiency.

Dennis Forbes
Friday, May 20, 2005

Note that 80-90% range means that your programm uses some other resources (I bet it uses all awailable IO bandwidth) that prevents it from going to 100%.

If you do use all available disk/network resources it is not too surprising tha all other apps are slow.

Check disk/network perf counters while your program is running to see if there are any areas to investigate...

Sunday, May 22, 2005

The problem isn't CPU usage, it's likely to be disk usage. If you wrote the perfect CPU consuming thread, that never touched an outside resource, and marked such a thread as low priority, it would have effectively zero impact on the system.

The problem is, disk I/O is being queued. You request a file, some other process requests a file after you. It doesn't matter that your thread is lower priority, because you're facing disk transfer and head seek times.

Brad Wilson [MSFT]
Sunday, May 22, 2005

*  Recent Topics

*  Fog Creek Home