Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does every 'HttpRequest' get its own thread in ASP.NET?

In ASP.NET, does every HttpRequest get its own thread?

Update - To clarify, I'm asking specifically about incoming requests.

like image 755
Dan Esparza Avatar asked Sep 12 '09 22:09

Dan Esparza


People also ask

How many worker threads in IIS?

The “hard” limit on the max number of threads in the IIS thread pool. This limit can be set to a value between 64 and 256, so you cannot have more than 256 IIS threads in the pool regardless of settings.

How many threads are there in asp net core?

So as in our case default threads are 12 which means the number of threads in the thread pool is 12 and when the 13th request comes it will look for a free thread and if all the threads are busy then it will spawn a new thread but will wait for some 0.5 seconds before it spawns a new thread.

Is HttpContext thread safe?

HttpContext access from a background threadHttpContext isn't thread-safe. Reading or writing properties of the HttpContext outside of processing a request can result in a NullReferenceException.

How to increase thread pool size in IIS?

To increase the value for the Threads Per Processor Limit follow these steps:In the Connections pane, select the web server, click to select Features View, and then double-click the ASP feature. Click Start, point to All Programs, click Administrative Tools, and then click Internet Information Services (IIS) Manager.


1 Answers

If you're referring to using the HttpRequest object for making outgoing requests from your application, no - HttpRequest runs in the current thread.

If you're referring to how IIS and ASP.NET handles threading per request, yes. Each request is run on a separate thread. However, the model is a little more complex than that - there are worker threads and I/O threads to consider. And under load, .NET will sometimes move requests from one thread to another as it sees fit. This is important to understand when dealing with things like ThreadStatic.

like image 167
Rex M Avatar answered Oct 03 '22 03:10

Rex M