views:

206

answers:

3

I have 15 BackgroundWorers that are running all the time, each one of them works for about half a second (making web request) and none of them is ever stopped.

I've noticed that my program takes about 80% of my computer's processing resources and about 15mb of memory (core 2 duo, 4gb ddr2 memory).

It it normal? web requests are not heavy duty, it just sends and awaits server response, and yes, running 15 of them is really not a pro-performance act (speed was needed) but i didn't think that it would be so intense.

I am new to programming, and i hardly ever (just as any new programmer, I assume) care about performance, but this time it is ridiculous, 80% of processing resources usage for a windows forms application with two listboxes and backgroundworkers making web requests isn't relly what expected.

info:

  • I use exception handling as part of my routine, which i've once read that isn't really good for performance
  • I have 15 background workers
  • My code assures none of them is ever idle
  • List item
  • windows forms, visual studio, c#.

------[edit - questions in answers]------

What exactly do you mean by "My code assures none of them is ever idle"?
The program remains waiting

while (bgw1.IsBusy || gbw2.IsBusy ... ... ...) { Application.DoWork();}

then when any of them is free, gets put back to work.

Could you give more details about the workload you're putting this under?
I make an HTTP web request object, open it and wait for the server request. It really has only a couple of lines and does no heavy processing, the half second is due to server awaiting.

In what way, and how many exceptions are being thrown? When the page doesn't exist, there is a system.WebException, when it works it returns "OK", and about 99% of the pages i check don't exist, so i'd say about 300 exceptions per minute (putting it like this makes it sound creepy, i know, but it works)

If you're running in the debugger, then exceptions are much more expensive than they would be when not debugging I'm not talking about running it in the debugger, I run the executable, the resulting EXE.

+1  A: 

This bit concerns me:

My code assures none of them is ever idle

What exactly do you mean by that?

If you're making thousands and thousands of web requests, and if those requests are returning very quickly, then that could eat some CPU.

Taking 15MB of memory isn't unexpected, but the CPU is the more worrying bit. Could you give more details about the workload you're putting this under? What do you mean by "each one of them workds for about half a second"?

What do you mean by "I use exception handling as part of my routine"? In what way, and how many exceptions are being thrown? If you're running in the debugger, then exceptions are much more expensive than they would be when not debugging - if you're throwing and catching a lot of exceptions, that could be responsible for it...

Jon Skeet
Questions answered, check update.
MarceloRamires
+2  A: 
while (bgw1.IsBusy || gbw2.IsBusy ... ... ...) { Application.DoWork();}

What's Application.DoWork(); doing? If it's doing something quickly and returning, this loop alone will consume 100% CPU since it never stops doing something. You can put a sleep(.1) or so inside the loop, to only check the worker threads every so often instead of continuously.

Wim
I did it, but then it doesn't let the bgw's change their IsBusy flags to false.. even with an Application.DoWork(); inside the loop.
MarceloRamires
A: 

Run the program in the debugger, pause it ten times, and have a look at the stacktraces. Then you will know what is actually doing when it's busy.

jdv