How is ASP.NET multithreaded? How is ASP.NET multithreaded? asp.net asp.net

How is ASP.NET multithreaded?


Not only does the server farm different requests to different threads, but a single request can change thread during the course of life cycle. This is called thread agility. I'm looking for a good article explaining it...

EDIT: No definitive articles yet, but one blog post explaining some of the difficulties.

EDIT: More links from comments:


ASP.net uses the .Net threadpool (which is configurable)Each request is received by one of the threads in the threadpool, until each thread is already occupied. Then requests queue at the IIS Stack, until this also spills over. From there new requests are meet with the very ugly 'Server is unavailable' message.

This is the usual 'multi-threading' story for a ASP.net website.

There are many ways to ensure scalability. The most obvious being performance testing and removing bottlenecks from your code.

ASP.net can really take advantage of multiple cores by utilizing the I/O threads for any I/O request. It makes for ugly code but fast has never been pretty.

Here is the definitive MSDN MAG post on how to do this

UPDATE

Well I probably attempt to answer your full question:

"More importantly is there any advantage to adding threads to ASP.Net code if the threading is done higher up in IIS?"

The short answer is: It depends!If you are waiting on a long running process, then you would be better advised to implement a nicer experience for the requesting client (i.e. Out of band AJAX calls)

if you have multiple independent tasks that need to be completed for the requesting client: then you might be better off spawning a new process to run the tasks in parallel.

If your site gets lots of traffic, then you really need to consider implementing Asynchronous patterns to better utilise your CPU


IIS makes use of the multiple cores automatically (although you can turn it off if you so choose).

The advantage to adding threads to ASP.NET code is so that you can control your own application's inner workings and not be forced to rely on IIS to make all the decisions for you.