Max threadpool count in ASP.NET 2.0

Onion Blog

Syndication

I noticed today that the maximum threadpool count in ASP.NET 2.0 is set to 100 worker and 100 I/O threads per cpu, and from what I can tell, these values are not easily modifiable. [Update: it actually is easily modifiable, just as it was in 1.1, using the processModel element in machine.config.] (You can check the threadpool maxima by calling ThreadPool.GetMaxThreads in any process). This is in contrast with 1.1 where the default was 20 worker and 20 I/O threads per cpu, which could be adjusted with the processModel element in machine.config.
 
This seems like a good decision overall to me. The threadpool will likely never max out at 100 even under heavy load because of the heuristics for thread allocation built into the threadpool. During some load testing, I couldn't even get the threadpool to allocate more than 30 threads with two client machines pummeling a server full bore. In 1.1 it was actually pretty easy to hit the 20 thread limit with any load, and if your requests were I/O-bound it actually became the limiting factor in the requests your server could handle.
 
Rather than tweaking the threadpool limits, however, developers should be focused on using the threads that are allocated to their requests efficiently, like using async I/O when possible, and tapping into the new async tasks and async page features of ASP.NET 2.0 when it makes sense.
 
Interestingly, if you check the threadpool maxima in a console or Winforms app, they are set to 25 worker threads and 1000 I/O threads (yes that's 1.0x10^3). It seems somewhat odd that the ASP.NET runtime changes the 1000 upper bound for I/O threads, which is obviously meant to mean 'unbounded' for all intents and purposes. I wonder if dropping it to 100 was intended as a real constraint (one you'd be unlikely to run into, although certainly more likely than 1000) or just a case of maintaining symmetry...
 

Limited training time? Need to learn ASP.NET 2.0 and SQL Server 2005?
Come join Fritz Onion and Dan Sullivan the week of July 17, 2006 in Waltham, MA for a
Pluralsight Double Feature: ASP.NET 2.0 and SQL Server 2005
Register today!

 

Posted Apr 11 2006, 01:23 PM by fritz-onion
Filed under:

Comments

Kiran Chand wrote re: Max threadpool count in ASP.NET 2.0
on 04-11-2006 2:02 PM
Actually it is not that difficult. If you want to change it (for any reason).. here is how you do it.

Open the machine.config.

Comment out the the existing processmodel element first and then add the element with the parameter as shown

<!--processModel autoConfig="true"/-->

<processModel
maxWorkerThreads="20"
minWorkerThreads="20"
/>

Fritz Onion wrote re: Max threadpool count in ASP.NET 2.0
on 04-11-2006 2:23 PM
Yep, that does indeed still work. I tried exactly that before posting this and saw no effect, so I assume they had disabled it - must have been something else wrong. Thanks Kiran!

Josh Twist wrote re: Max threadpool count in ASP.NET 2.0
on 04-12-2006 1:03 AM
Hi Fritz

I've been doing a lot of work with the ThreadPool recently and have a number of recent posts on my blog that are very relevant to this topic that may interest you and your readers:

http://www.thejoyofcode.com/Tuning_the_ThreadPool.aspx
http://www.thejoyofcode.com/ThreadPool_Settings_in_machine.config_.aspx
http://www.thejoyofcode.com/More_fun_with_Thread_Pools.aspx

Enjoy!

Josh
Trilok wrote re: Max threadpool count in ASP.NET 2.0
on 01-17-2007 12:22 AM
It seems that the default for MaxWorkerThreads and MaxIOThreads is 20 in net 2.0 too.
Refer http://msdn2.microsoft.com/en-us/library/system.web.configuration.processmodelsection.maxworkerthreads(VS.80).aspx

Unfortunately, the excellent perf and scalability guide still gives values about .Net version 1.0 and 1.1 - and does not discuss 2.0 in this section.
Fritz Onion wrote re: Max threadpool count in ASP.NET 2.0
on 01-17-2007 5:06 AM
Actually, I just did another quick test, and on the current drop of 2.0 the thread pool max counts are 200 - it's easy to test:

int wtpm, iotpm;
ThreadPool.GetMaxThreads(out wtpm, out iotpm);

-Fritz
Marko Lahma wrote re: Max threadpool count in ASP.NET 2.0
on 05-04-2007 3:28 AM
Was this with SP1 applied? I think they have changed the behavior in the SP1 to allow a lot more than in the initial release.

-Marko

Add a Comment

(required)  
(optional)
(required)  
Remember Me?