Uncategorized

minWorkerThreads and autoConfig

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.

First thing, to be on the safe side I set autoConfig=”false” (see why here) and set my <processModel> element as follows:

<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):

0:029> !threadpool
CPU utilization 48%
Worker Thread: Total: 2 Running: 0 Idle: 2 MaxLimit: 40 MinLimit: 2
Work Request in Queue: 0
--------------------------------------
Number of Timers: 8
--------------------------------------
Completion Port Thread:Total: 1 Free: 1 MaxFree: 4 CurrentLimit: 0 MaxLimit: 40 MinLimit: 2

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:

0:030> !threadpool
CPU utilization 7%
Worker Thread: Total: 2 Running: 0 Idle: 2 MaxLimit: 200 MinLimit: 46
Work Request in Queue: 0
--------------------------------------
Number of Timers: 8
--------------------------------------
Completion Port Thread:Total: 1 Free: 1 MaxFree: 4 CurrentLimit: 0 MaxLimit: 200 MinLimit: 2

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 maxWorkerThreads attribute
The maxIoThreads attribute
The minFreeThreads attribute of the httpRuntime element.
The minLocalRequestFreeThreads attribute of the httpRuntime element
The maxConnection attribute of the <connectionManagement> Element (Network Settings) element.

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.

Not quite…

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:

  1. Always keep an eye on default values
  2. Keep the other eye on how default values influence each other
  3. 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

Carlo

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.