Geeks With Blogs

News
Stuart Brierley Integration Management - BizTalk and More

Recently I needed to try and reduce contention within IIS when calling a number of web services.  Eventually this led to the need to make some changes to the machine.config file.

The changes identified were based on the Microsoft recommended settings.  These recommended values should be viewed as a start point for continued tuning, but have been shown to work in most circumstances.  They are based on the premise that for each ASPX page in use you are making one Web service call to a single IP address.

It is only suggested that you try this in situations where you are performing operations such as calling Web Services or accessing files (IO processes) and you have some available processing power.

It is not recommended that these changes be applied in isolation, as this causes problems.  Similarly, setting these values incorrectly can also cause problems.  

Some of these recommendations involve a simple formula that involves the number of CPUs on a server.  Where hyperthreading is enabled, you should base the calculation on the number of logical CPUs and not the number of physical CPUs.

i.e. On a two-processor server with hyperthreading enabled, you should be calculating these settings based on 4 CPUs not 2.

The recommendations I followed are detailed below, followed by an example of these setting in the machine.config file.  I have also included a couple of links that hepled me identify the changes I needed; these may be of interest if you want to read into this further.

The machine.config file can be found in the \WINDOWS\Microsoft.NET\Framework\vXXXX\CONFIG directory.

 

maxconnection

Controls the maximum number of outgoing HTTP connections that you can initiate from a client to a specific IP address.

Setting the address attribute to * applies this value to all addresses.  You can include multiple entries for this setting to control the maximum number of connections to specific IP addresses.

The maxconnection parameter setting applies at the AppDomain level. By default, you can create a maximum of two connections to a specific IP address from each AppDomain in your process.

This setting is not automatically multiplied by the number of available CPUs, you must do this yourself.

Default                              2
Recommended              12 * Number of CPUs 

 

maxIoThreads

Controls the maximum number of I/O threads in the .NET thread pool. 

This number is automatically multiplied by the number of available CPUs.

Default                              20
Recommended              100
 


maxWorkerThreads                 

Controls the maximum number of worker threads in the thread pool.


This number is then automatically multiplied by the number of available CPUs.

Default                              20
Recommended              100
 

minWorkerThreads

Determines how many worker threads may be made available immediately to service a remote request.  This can be useful when there may be sudden rise in the number of requests, such as a burst of requests from another server or from client users.  This enable ASP.NET to service requests that may be suddenly filling the ASP.NET request queue. 


This number is then automatically multiplied by the number of available CPUs.


Default                              1
Recommended              maxWorkerThreads / 2
 

minIoThreads

Determines how many of I/O threads may be made available immediately in the .NET thread pool.

This number is then automatically multiplied by the number of available CPUs.

Default                              1
Recommended              maxIoThreads / 2


minFreeThreads

Used by the worker process to queue all the incoming requests.  This only applies if the number of available threads in the thread pool falls below the value for this setting.

This setting is not automatically multiplied by the number of available CPUs, you must do this yourself.

This setting effectively limits the number of requests that can run concurrently to maxWorkerThreads - minFreeThreads .

Default                              8                                 
Recommended              88 * Number of CPUs

Following the recommendation above limits the number of concurrent requests to 12 per CPU (assuming maxWorkerThreads is 100) because 100 - 88 = 12.  This leaves at least 88 worker threads per CPU and 88 completion port threads per CPU available for other uses (such as for the Web service callbacks).


minLocalRequestFreeThreads            

Used by the worker process to queue requests from localhost, such as requests to a local Web service.  This only applies if the number of available threads in the thread pool falls below this number.

This setting is not automatically multiplied by the number of available CPUs, you must do this yourself.

This setting is similar to minFreeThreads but it only applies to localhost requests from the local computer.

Default                              4
Recommended              76 * Number of CPUs 
 

Example

An example of how these entries might look in the machine.config file is shown below.  This is an edited version of this file, focusing only on those settings discussed above.

 <configuration>
 <system.net>
         <connectionManagement>
             <add address="*" maxconnection="24" />
         </connectionManagement>
     </system.net>
     <system.web>
         <processModel autoConfig="true"
             maxWorkerThreads = "100"
             maxIoThreads = "100"
             minWorkerThreads = "50"
             minIoThreads = "50"
         />
         <httpRuntime
             minFreeThreads="176"
             minLocalRequestFreeThreads="152"
         />
     </system.web>
</configuration>

 

Links

Contention, poor performance, and deadlocks when you make Web service requests from ASP.NET applications

IIS 6.0 Tuning for Performance

Posted on Wednesday, September 30, 2009 3:56 PM ASP.Net / VB.Net / C# / IIS | Back to top


Comments on this post: Tuning IIS - machine.config settings

# re: Tuning IIS - machine.config settings
Requesting Gravatar...
I recently ran into issue where my machine.config values were not getting picked up, this article helped me. A pointer to the audience of this blog:

http://www.altafkhatri.com/Technical/Configure/Common_ASP_NET/Machine_Config_Values_Not_Picking_up_Solution_Reso
Left by Dyllon Jason on Nov 18, 2011 12:16 AM

# re: Tuning IIS - machine.config settings
Requesting Gravatar...
Hi
Nice article! Just am a bit doubtful about the last example. If autoConfig attribute is set to true, will all the values that are set manually be considered? Whatever I have checked till now says autoConfig should be false for imposing manual values.
Left by Muktesh on Dec 17, 2012 9:54 AM

Your comment:
 (will show your gravatar)
 


Copyright © Stuart Brierley | Powered by: GeeksWithBlogs.net | Join free