Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is ASP.NET multithreaded?

Tags:

I've been told that ASP.NET is multithreaded by default in IIS. How is this threading achieved?

Does the server farm send different requests to different cores?

Does a single request make use of multiple cores?

More importantly, are there any advantages to adding threads to ASP.NET code if the threading is done higher up in IIS?

like image 843
Craig Warren Avatar asked Mar 18 '09 10:03

Craig Warren


People also ask

Is ASP.NET single threaded?

In short, ASP.NET is multithreaded and when processing a particular request, may even switch to another thread at particular steps during the request life cycle (and it could be worse with async pages).

How many threads does ASP.NET use?

ASP.NET Threading Inside the ASP.NET Worker Process, there are two thread pools. The worker thread pool handles all incoming requests and the I/O Thread pool handles the I/O (accessing the file system, web services and databases, etc.).

What is multithreading in ASP NET MVC?

The first is that every ASP.NET application (MVC or otherwise) is inherently multi-threaded: Each request will be processed on a separate thread, so you are automatically in a multi-threading situation and must consider this with any shared access to data (e.g. statics, etc.).

How does multithreading work in C#?

Thread class is used for working with threads. It allows creating and accessing individual threads in a multithreaded application. The first thread to be executed in a process is called the main thread. When a C# program starts execution, the main thread is automatically created.


1 Answers

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 Thread Switching (blog post)
  • What is an "async IO operation" in .NET? (SO question; sounds irrelevant but isn't)
  • ASP.NET and System.Diagnostics tracing (SO question)
  • Threading differences between IIS 6 and 7
like image 55
Jon Skeet Avatar answered Sep 19 '22 11:09

Jon Skeet