Groups | Blog | Home
all groups > dotnet performance > march 2005 >

dotnet performance : Async operations taking 100% of CPU


Edgardo Rossetto
3/22/2005 9:14:36 AM
I'm in need to download big files using async operations, I've done my
implementation based on this example:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnethttpwebrequestclassbegingetresponsetopic.asp

im facing the problem that after 1-2 seconds the CPU usage raises to
100%, I'm not storing the bytes downloaded in strings, in fact i'm not
saving these bytes at all (for the moment).

In fact, take that sample, make no use of the StringBuilder (suppose
we'll save the bytes later into a file) and try it with a big file (say
50mb)

Running the release version, CPU usage still raises 100%.

Is this a problem of the approach of this example? or is it a problem
with the framework?

Can someone point me to some direction here please?

Thanks,
David Browne
3/22/2005 11:41:22 AM

[quoted text, click to view]

No. It's a problem with your implementation. Async downloading of large
files will take very little CPU.

Are you sure you need to use Async IO? As you have discovered, it can be a
bit tricky. Can't you just spawn a thread to download the file? It's much
easier to implement and unless you are downloading hundreds of files
simultaneously, you won't see any real benefit from the async approach.


David

David Browne
3/22/2005 10:33:24 PM

[quoted text, click to view]

I have no idea what's wrong with your implementation. Perhaps if you posted
it. . .

David

Edgardo Rossetto
3/22/2005 11:25:46 PM
[quoted text, click to view]

I decided to use the async approach because I need to (optionally)
update the UI from the main thread, and I read that it was more
complicated using threads.

What is exactly wrong with my implementation?

I've also tried these 2 examples:

http://www.codeproject.com/csharp/webdownload.asp
http://www.codeproject.com/useritems/CoolDownloader.asp

The first one is very much like my implementation (also it seems to be
based on the MSDN example), and again, on a 50mb files it reaches 100%
of CPU usage in 1-2 secs, even worse, it consumes a lot of memory since
its storing the whole file in memory.

The second uses threads and non-async downloading, storing the buffer
into a file and and guess what? 100% CPU in 1-2 secs.

I really dont know whats wrong here. :(


AddThis Social Bookmark Button