修改machine.Config 提高iis性能
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>
参考地址:
http://www.iis.net/ConfigReference/system.applicationHost/applicationPools/add/cpu
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?