关于machine.config的那些事儿

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>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值