支持高並發的IIS Web服務器常用設置


適用的IIS版本:IIS 7.0, IIS 7.5, IIS 8.0

適用的Windows版本:Windows Server 2008, Windows Server 2008 R2, Windows Server 2012

1、應用程序池(Application Pool)的設置: 

  • General->Queue Length設置為65535(隊列長度所支持的最大值)
  • Process Model->Idle Time-out設置為0(不讓應用程序池因為沒有請求而回收)
  • Recycling->Regular Time Interval設置為0(禁用應用程序池定期自動回收)

2、.Net Framework相關設置

a) 在machine.config中將

<processModel autoConfig="true" />

改為

<processModel enable="true" requestQueueLimit="100000"/>

(保存后該設置立即生效)

b) 打開C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\Browsers\Default.browser,找到<defaultBrowser id="Wml" parentID="Default" >,注釋<capabilities>部分,然后運行在命令行中運行aspnet_regbrowsers -i

<defaultBrowser id="Wml" parentID="Default" >
    <identification>
        <header name="Accept" match="text/vnd\.wap\.wml|text/hdml" />
        <header name="Accept" nonMatch="application/xhtml\+xml; profile|application/vnd\.wap\.xhtml\+xml" />
    </identification>
<!--
    <capabilities>
        <capability name="preferredRenderingMime"              value="text/vnd.wap.wml" />
        <capability name="preferredRenderingType"              value="wml11" />
    </capabilities>
-->
</defaultBrowser>

以解決text/vnd.wap.wml問題。

3、IIS的applicationHost.config設置

設置命令:

c:\windows\system32\inetsrv\appcmd.exe set config /section:serverRuntime /appConcurrentRequestLimit:100000

設置結果:

<serverRuntime appConcurrentRequestLimit="100000" />

(保存后該設置立即生效)

4、http.sys的設置

注冊表設置命令1(將最大連接數設置為10萬):

reg add HKLM\System\CurrentControlSet\Services\HTTP\Parameters /v MaxConnections /t REG_DWORD /d 100000

注冊表設置命令2(解決Bad Request - Request Too Long問題):

reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters /v MaxFieldLength /t REG_DWORD /d 32768
reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters /v MaxRequestBytes /t REG_DWORD /d 32768

(需要在命令行運行 net stop http  & net start http & iisreset 使設置生效)

5、針對負載均衡場景的設置

在Url Rewrite Module中增加如下的規則:

<rewrite>
    <allowedServerVariables>
        <add name="REMOTE_ADDR" />
    </allowedServerVariables>
    <globalRules>
        <rule name="HTTP_X_Forwarded_For-to-REMOTE_ADDR" enabled="true">
            <match url=".*" />
            <serverVariables>
                <set name="REMOTE_ADDR" value="{HTTP_X_Forwarded_For}" />
            </serverVariables>
            <action type="None" />
            <conditions>
                <add input="{HTTP_X_Forwarded_For}" pattern="^$" negate="true" />
            </conditions>
        </rule>
    </globalRules>
</rewrite>

相關博文:遷入阿里雲后遇到的Request.UserHostAddress記錄IP地址問題

注意事項:添加該URL重寫規則會造成IIS內核模式緩存不工作,詳見微軟的坑:Url重寫竟然會引起IIS內核模式緩存不工作

6、 設置Cache-Control為public

在web.config中添加如下配置: 

<configuration>
    <system.webServer>
        <staticContent>
            <clientCache cacheControlCustom="public" />
        </staticContent>
    </system.webServer>
</configuration>

7、ASP.NET線程設置

在machine.config的<processModel>中添加如下設置: 

<processModel enable="true" maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50" minIoThreads="50"/>

相關博文:雲計算之路-阿里雲上:從ASP.NET線程角度對“黑色30秒”問題的全新分析

8、修改TCP MaxUserPort限制

由默認5000改為65534,修改方法:在注冊表 HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters 中添加名為MaxUserPort,類型為DWORD(32-bit),值為65534(10進制)的項目並重啟計算機。

相關博文:超出TCP連接端口數限制(MaxUserPort)引起的服務器問題

 

相關鏈接:

讓Windows Server 2008 + IIS 7+ ASP.NET 支持10萬並發請求


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM