joydip_kanjilal
Contributor

How to tune machine.config settings for improved performance

opinion
Feb 26, 20164 mins
Software Development

Explore ways to tweak the settings in machine.config file for improved performance

Tweaking the settings in your configuration files in ASP.Net can provide a nice performance boost. These files include machine.config and web.config.

The web.config file is application-specific and is created by default when you create a web application or a web site in Visual Studio. Note that there is another config file named aspnet.config — it is available from ASP.Net 2.0 onwards. This file is available in the root of the .Net Framework folder in your system. The machine configuration file, meanwhile,  is named machine.config and resides in the %runtime install path%Config directory.

While the settings in the web.config file apply only to the application, the settings present in the machine.config file are applicable machine-wide. Note that the machine.config file is installed when you install .Net Framework in your system. You can have only one machine.config file in your system (one per system only) and it resides in the WINDOWSMicrosoft.NetFrameworkvXXXXCONFIG directory.

It should be noted that the settings defined in the machine.config file is overridden by those defined in the web.config file in your application. An application can have multiple web.config files. Incidentally, the web.config file inherits the settings defined in the machine.config.

Recommended machine.config settings

In this section we will explore the settings that can be applied to the machine.config file for performance gains. Note that the default and recommended values have been specified against each setting.

maxconnection

You can tweak the system.Net settings in your machine.config file to allow more concurrent requests to be served by your application. The default value is 2 while the recommended value is 12 per CPU.

<system.Net>

    <connectionManagement>

        <add address="*" maxconnection="24"/>

    </connectionManagement>

</system.Net>

Here are the recommended settings for the process model section in your machine.config file for performance benefits. You can tweak the settings in the process model in your machine.config file to control worker threads, I/O threads, etc. Note that a thread is the smallest unit of execution within a process.

memoryLimit

This setting is used to specify the percentage of the total system memory that the process would use. The default value is 40. The recommended value for this setting depends on many factors. Such considerations include (but are not limited to) the following:

  • If the application is installed in an isolated box
  • Occurrence of memory leaks in the application

maxWorkerThreads

This setting is used to define the maximum number of worker threads that are available in the thread pool at any given point of time. A thread pool comprises of a number of threads, or, a collection of threads to be precise, and it can be used to perform several activities in the background. The MSDN states: “A thread pool is a collection of worker threads that efficiently execute asynchronous callbacks on behalf of the application. The thread pool is primarily used to reduce the number of application threads and provide management of the worker threads.”

The default value of maxWorkerThreads is 20 per CPU and the recommended value is 100.

minWorkerThreads

This setting determines the minimum number of worker threads that are available in the thread pool to satisfy an incoming request. The default value is 1 while the recommended value is maxWorkerThreads / 2. So if you have defined maxWorkerThreads as 100 in your machine.config file, you should specify 50 as minWorkerThreads.

maxIOThreads

This setting is used to define the maximum number of threads that are allotted for performing input output (I/O) operations. Such operations include database operations, calls to web services, accessing the file system, etc. The default value is 20 per CPU while a value of 100 is recommended.

minIOThreads

This is used to define the minimum number of I/O threads that are available in the thread pool at a particular point of time. The default value is 1 while the recommended value is maxIOThreads / 2. So, if you have defined maxIOThreads as 100 in your machine.config file, you should mention 50 as minIOThreads.

Put it all together

Let’s now put all of these settings to work. The following code listing illustrates the typical settings in a machine.config file based on the recommended settings described earlier in the article.

<configuration>

 <system.Net>

         <connectionManagement>

             <add address="*" maxconnection="24" />

         </connectionManagement>

     </system.Net>

     <system.web>

         <processModel autoConfig="true"

             maxWorkerThreads = "100"

             maxIoThreads = "100"

             minWorkerThreads = "50"

             minIoThreads = "50"

         />

     </system.web>

</configuration>

joydip_kanjilal
Contributor

Joydip Kanjilal is a Microsoft Most Valuable Professional (MVP) in ASP.NET, as well as a speaker and the author of several books and articles. He received the prestigious MVP award for 2007, 2008, 2009, 2010, 2011, and 2012.

He has more than 20 years of experience in IT, with more than 16 years in Microsoft .Net and related technologies. He has been selected as MSDN Featured Developer of the Fortnight (MSDN) and as Community Credit Winner several times.

He is the author of eight books and more than 500 articles. Many of his articles have been featured at Microsoft’s Official Site on ASP.Net.

He was a speaker at the Spark IT 2010 event and at the Dr. Dobb’s Conference 2014 in Bangalore. He has also worked as a judge for the Jolt Awards at Dr. Dobb's Journal. He is a regular speaker at the SSWUG Virtual Conference, which is held twice each year.

More from this author