A couple of days ago I was helping a colleague of mine with some tests and I had the need to change the ThreadPool configuration; more precisely, I wanted to increase the minWorkerThreads value. Everything was working fine at first, because I was changing the value by code using the SetMinThreads method, but I also wanted to test it changing the values from my machine.config.
<processModel autoConfig=”false” minWorkerThreads=”23” />
Why set it to 23? Simply because I did not want it to match any default.
I run my test page, attached Windbg to the process and had a look at !threadpool output: something was definitely wrong, as it was telling that minWorkerThreads was set to 2 (the default value is 1 * CPU number = 2 for my machine):
Now I see from here and with some reasoning, it is already possible to understand why I was not seeing MinLimit=46 as I was expecting… Who has the eagle eye?
I was in a hurry (as usual) and I tried a few other things, one of them was to set autoConfig back to true, here is what I got:
This time I’m getting it as I wanted! I’m sure someone already got it…
But before going to the solution, let’s just explain why this cannot be because of autoConfig as you may think
Here is how MSDN defines autoConfig:
Specifies whether to automatically configure the following settings to achieve optimal performance based on the machine configuration:
The values are set according to the KB article at http://support.microsoft.com/?id=821268.
This attribute does not affect the .NET Framework client applications; only ASP.NET applications.
The autoConfig attribute can be one of the following values.
- True: Indicates that ASP.NET automatically configures the attributes in the preceding list to achieve optimal performance based on the machine configuration.
- False: Indicates that ASP.NET should use the explicitly defined values for the attributes in the preceding list.
The default in the Machine.config file is True, unless there is a previously existing configuration.
minWorkerThreads is not one of the values automatically configured by the runtime, so whether autoConfig is true or false does not make any difference.
Have another look at the !threadpool output above: with autoConfig=”true” the ThreadPool limit for maxWorkerThreads is 200 (100 * 2 CPUs), while with autoConfig=”false” maxWorkerThreads is set to 40 (default 20 * 2 CPUs).
As you can imagine, it is not possible to set minWorkerThreads higher than maxWorkerThreads… The runtime detects the inconsistency and simply set the “min” value to its default.
So I have 3 points to make:
- Always keep an eye on default values
- Keep the other eye on how default values influence each other
- Ok, I lied, just a bit… autoConfig does not directly influence minWorkerThreads and minIoThreads, but they are instead affected by their counterparts such as maxWorkerThreads and maxIoThreads
Quote of the day:
Technology is dominated by two types of people: those who understand what they do not manage, and those who manage what they do not understand. – Putt's law