I
icesunny
I posted this at dotnet.general a few days ago, but as far as there was
no answer, I'll repost it here. I you think that there is even more
appropriate group for this, please let me know, and I'll repost. Thanks.
<Repost>
Hi,
I read a lot of articles about deadlocks and ThreadPool overloading when
a lot of WebService or WebRequests are made from and ASP.NET
applications. In most of these articles and examples there is a
statement, that HttpWebRequest.GetResponse() call is always executed
asyncronously in v. 1.x of the network. I used Reflector to examine
this, and indeed, the code looks like:
BeginGetRequest(...);
.......
EndGetRequest();
Now, I created a test console application, which invokes a simple web
service. This service only invokes Thread.Sleep for the number of
seconds passed as parameter. Note - this is for .Net v.1.1 SP1.
My test application starts 3 threads (not from the threadpool). The
first one prints on console the current ThreadPool free threads. And the
other 2 make invocation of the sample web service (not using a proxy,
but pure GET request, using HttpWebRequest class), requesting delays of
10 and 20 seconds.
Now, the strange thing is, that I do not see any thread of the
ThreadPool used while waiting for the HttpResponse, I.e. this behaves
very differently from what I read so far about how HttpRequests are
made.
I tried to invoke HttpWebRequest in 3 different ways (just comment and
uncomment the corresponding 2 lines in the Main method):
1. A custom thread just invokes the synchronous GetResponse method - no
threadpool usage is visible, even as per the articles I mentioned, it
should translate in async invocation internally.
2. A threadpool thread invokes synchronous GetResponse - then obviously
a threads from the pool are used, but only the ones, which make the
call, but still not visible another threadpool thread which is used by
the GetResponse.
3. A custom thread, which invokes async GetResponse (with
BeginGetResponse/EndGetResponse), as well as async reading of the
response stream. Still I can not see a threadpool thread to be used.
Can somebody explain this behaviour? Why this sample works not like it
should be? If all these articles are wrong, should I worry if I have a
async web service, which internally invokes a 100-200 HttpRequests per
invocation. I may have more than 300 invocations of that service in the
same time?
Actually, what I'm after is a web service, which will be used by more
than 300 clients at the same time, which by itself retrieves 100-200 web
pages per request. I want to speedup the process, and to use all
available resources to fetch as many pages as possible at a time using
threads.
At the following URL you can find a zip with the source files I used.
You need to set your IIS virtual directory to map to the test web
service:
http://216.17.90.93/ThreadTest.zip
These are the articles I read on the topic:
<http://msdn.microsoft.com/msdnmag/issues/04/12/NETMatters/>
<http://www.deez.info/sengelha/blog/2005/03/03/beware-threadpools-and-
httpwebrequest/>
<http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/dnservice/html/service07222003.asp>
<http://msdn.microsoft.com/msdnmag/issues/03/06/Threading/>
Cheers
Sunny
no answer, I'll repost it here. I you think that there is even more
appropriate group for this, please let me know, and I'll repost. Thanks.
<Repost>
Hi,
I read a lot of articles about deadlocks and ThreadPool overloading when
a lot of WebService or WebRequests are made from and ASP.NET
applications. In most of these articles and examples there is a
statement, that HttpWebRequest.GetResponse() call is always executed
asyncronously in v. 1.x of the network. I used Reflector to examine
this, and indeed, the code looks like:
BeginGetRequest(...);
.......
EndGetRequest();
Now, I created a test console application, which invokes a simple web
service. This service only invokes Thread.Sleep for the number of
seconds passed as parameter. Note - this is for .Net v.1.1 SP1.
My test application starts 3 threads (not from the threadpool). The
first one prints on console the current ThreadPool free threads. And the
other 2 make invocation of the sample web service (not using a proxy,
but pure GET request, using HttpWebRequest class), requesting delays of
10 and 20 seconds.
Now, the strange thing is, that I do not see any thread of the
ThreadPool used while waiting for the HttpResponse, I.e. this behaves
very differently from what I read so far about how HttpRequests are
made.
I tried to invoke HttpWebRequest in 3 different ways (just comment and
uncomment the corresponding 2 lines in the Main method):
1. A custom thread just invokes the synchronous GetResponse method - no
threadpool usage is visible, even as per the articles I mentioned, it
should translate in async invocation internally.
2. A threadpool thread invokes synchronous GetResponse - then obviously
a threads from the pool are used, but only the ones, which make the
call, but still not visible another threadpool thread which is used by
the GetResponse.
3. A custom thread, which invokes async GetResponse (with
BeginGetResponse/EndGetResponse), as well as async reading of the
response stream. Still I can not see a threadpool thread to be used.
Can somebody explain this behaviour? Why this sample works not like it
should be? If all these articles are wrong, should I worry if I have a
async web service, which internally invokes a 100-200 HttpRequests per
invocation. I may have more than 300 invocations of that service in the
same time?
Actually, what I'm after is a web service, which will be used by more
than 300 clients at the same time, which by itself retrieves 100-200 web
pages per request. I want to speedup the process, and to use all
available resources to fetch as many pages as possible at a time using
threads.
At the following URL you can find a zip with the source files I used.
You need to set your IIS virtual directory to map to the test web
service:
http://216.17.90.93/ThreadTest.zip
These are the articles I read on the topic:
<http://msdn.microsoft.com/msdnmag/issues/04/12/NETMatters/>
<http://www.deez.info/sengelha/blog/2005/03/03/beware-threadpools-and-
httpwebrequest/>
<http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/dnservice/html/service07222003.asp>
<http://msdn.microsoft.com/msdnmag/issues/03/06/Threading/>
Cheers
Sunny