Groups | Blog | Home
all groups > dotnet remoting > april 2005 >

dotnet remoting : Asynchronous Remoting and its effects on ASP.NET Threading


Stewart Rogers
4/28/2005 10:58:01 AM
Hi all,
Now I know that we can call .NET remoting components asynchronously from
ASP.NET pages and it works like a charm! But I am concerned about the
behavior of the overall system in this case and how does ASP.NET handle
threads.

(1) Lets say I asynchronously call .NET remoting component and redirects
user to a page. What happens to the ASP.NET thread that called the remoting
component asynchronously? Does that thread get stuck until the call actually
completes or the thread aborts as soon as the HTTP request is completed?

(2) What if I pass null in the last two parameters (AsyncCalback and object)
of the delegate BeginInvoke method?

I tried passing null in last two parameters of the BeginInvoke call and it
works fine!

What I am trying to figure out for sure is the "threading behavior" in case
of making asynchronous calls from ASP.NET pages because I don't want to do
anything that might affect the server threading because the application I am
working is supposed to be hit by thousands of users and scalability is a big
issues for me!

Could you guys pls answer the above questions and throw some light on the
ASP.NET threading and its behavior in case of asynchronous remoting.

Thanks,
Alvin Bruney [MVP - ASP.NET]
4/28/2005 10:12:33 PM
ASP.NET handles threading the usual way. A thread from the pool is used to
handle the request. A call, any call, executes the calling code.
Asynchronous calls return immediately, the called asynchronous code fires on
its own thread. The caller - main thread - moves on. For asynchronous calls
with callbacks, if there is nothing to call back to, nothing happens. You
have to be careful with callbacks and delegates because by the time these
calls get executed, the context may not be around resulting in a null
reference exception.

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
[quoted text, click to view]

Stewart Rogers
4/29/2005 6:14:02 AM
Thanks for your response Alvin but I still have some questions, mostly
regarding threading.

(1) Looks like there will be two different thread pools involved when using
remoting in ASP.NET. One pool would be ASP.NET worker thread pool whereas the
other one would be .NET remoting thread pool. am I right?

(2) I understand that ASP.NET uses worker threads to service the HTTP
request and that thread comes from ASP.NET's own pool of threads. Is that
thread returned to the ASP.NET worker thread pool after dispatching the
asynchronous call?

(3) You said that "the called asynchronous code fires on its own thread".
Who supplies that thread? ASP.NET worker thread pool or the .NET remoting
thread pool?

(4) You said that "The caller - main thread - moves on". I think you are
referring to the ASP.NET worker thread that invoked the component. am I right?

(5) You said "For asynchronous calls with callbacks, if there is nothing to
call back to, nothing happens". That means if I pass null in both of the
parameters to BeginInvoke call then I should be ok. Any thoughts?

I know these are quite a few questions to answer but a through/detailed
reply will help me understand the threading behavior.

Thanks for your all of your help; I highly appreciate that.

Stewart

[quoted text, click to view]
Alvin Bruney [MVP - ASP.NET]
5/3/2005 7:47:54 PM
1. not exactly, both pools are actually the same pool. there are 25 worker
threads for asp.net and 25 more for IO related activities. That's it. There
aren't anymore available.

2. yes. the beauty of the thread pool is that once a queued item is thru
servicing, it returns back to the pool.

3. see 1.

4. yes. call execution occurs sequentially from the main thread's
perspective. If the sequential call fires an asynchronous object, it simple
returns. the async object then executes on its own thread. If the object is
not an async object, then the main thread waits for the completion of the
call.


5. Yup. that's right.
Quoting the docs:
An array of type Object to pass as arguments to the given method. This can
be a null reference (Nothing in Visual Basic) if no arguments are needed.



--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
[quoted text, click to view]

Ice
5/3/2005 9:59:10 PM
you just need to be careful that you don't starve the threadpool by too many
asynchronous calls. Everything async uses a thread from the thread pool.

ice
[quoted text, click to view]

AddThis Social Bookmark Button