IIS 之 在IIS7、IIS7.5中應用程序池最優配置方案


  找到Web站點對應的應用程序池,“應用程序池” → 找到對應的“應用程序池” → 右鍵“高級設置...”

  

一、一般優化方案

  1、基本設置

  [1] 隊列長度: 默認值1000,將原來的隊列長度改為 65535。

  [2] 啟動32位應用程序:默認值False,改為True, 否則安裝一些32的組建或32位的php都會出錯。

  [3] 托管管道模式:Integrated 或 Classsic。 

  

  2、高級設置

  [1] 閑置超時(分鍾):默認20分鍾,修改設長。

  [2] 快速故障防護 → 已啟用 :默認True,改為False。 

  

  3、解決PEP第一次打開PEP速度慢

  回收間隔時間

  

  使用windows server 2008 r2解決回收假死的問題

  打開應用程序池 -> 高級設置 ->在“禁止重疊回收”里選擇“true”,這樣就有效避免了應用程序池回收假死問題。

  

二、支持同時10萬個請求

  通過對IIS7的配置進行優化,調整IIS7應用池的隊列長度,請求數限制,TCPIP連接數等方面,從而使WEB服務器的性能得以提升,保證WEB訪問的訪問流暢。

  站點碰到如下問題:

  Error Summary:

  HTTP Error 503.2 - Service Unavailable
  The serverRuntime@appConcurrentRequestLimit setting is being exceeded.

  Detailed Error Information:

  Module IIS Web Core
  Notification BeginRequest
  Handler StaticFile

  Error Code 0x00000000

  由於之前使用的是默認配置,服務器最多只能處理5000個同時請求,今天下午由於某種情況造成同時請求超過5000,從而出現了上面的錯誤。

  為了避免這樣的錯誤,我們根據相關文檔調整了設置,讓服務器從設置上支持10萬個並發請求。

  具體設置如下:

  1. 調整IIS 7應用程序池隊列長度

  將原來的隊列長度由默認值 1000 改為 65535。當然這里的隊列長度你可以根據自己的 訪問用戶*1.5 來設置,例如:有2000用戶,此處就可以設置為3000(3000=2000用戶數*1.5)。

  2.  調整IIS 7的appConcurrentRequestLimit設置

  由原來的默認5000改為100000。

  [1] 在cmd中執行:

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

  [2] 在%systemroot%\System32\inetsrv\config\applicationHost.config中可以查看到該設置:

  <serverRuntime appConcurrentRequestLimit="100000" />

  

  

  3. 調整machine.config中的processModel>requestQueueLimit的設置

  [1] 單擊“開始”,然后單擊“運行”,或者 windows + R。

  [2] 在“運行”對話框中,鍵入 notepad %systemroot%\Microsoft.Net\Framework64\v4.0.30319\CONFIG\machine.config,然后單擊“確定”。(不同的.NET版本路徑不一樣,可以選擇你自己當前想設置的.NET版本的config)

  [3] 找到如下所示的 processModel 元素:<processModel autoConfig="true" />

  [4] 將 processModel 元素替換為以下值:<processModel enable="true" requestQueueLimit="15000" />

  

  [5] 保存並關閉 Machine.config 文件。
  由原來的默認5000改為100000。

<configuration>
    <system.web>
        <processModel enable="true" requestQueueLimit="100000"/>

  參考文章:http://technet.microsoft.com/en-us/library/dd425294(office.13).aspx

  4. 修改注冊表,調整IIS 7支持的同時TCPIP連接數

  由原來的默認5000改為100000。在cmd中執行:

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

  

  可在注冊表中查看

  

  5. 運行命令使用設置生效

  net stop http  & net start  http & iisreset

  完成上述5個設置,就可以支持10萬個並發請求,博客園博客服務器已經啟用上述設置。

  為了方法大家與自己使用,我把上面能用bat操作簡單放到一個bat文件里面了。將下面的內容保存為do.bat文件運行就可以了,需要手工的自己操作

#appConcurrentRequestLimit
c:\windows\system32\inetsrv\appcmd.exe set config /section:serverRuntime /appConcurrentRequestLimit:100000
 
reg add HKLM\System\CurrentControlSet\Services\HTTP\Parameters /v MaxConnections /t REG_DWORD /d 100000
 
# 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
 
#更多的可以可以查看這篇文章,手工操作的可以查看這篇文章
start "C:\Program Files\Internet Explorer\iexplore.exe" <a href="http://www.jb51.net/article/36073.htm">http://www.jb51.net/article/36073.htm</a>

 

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

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

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

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

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

  2、.Net Framework相關設置

  [1] 在machine.config中將
  < processModel autoConfig="true" />

  改為

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

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

  [2] 打開C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\Browsers\Default.browser,找到<defaultBrowser id="Wml" parentID="Default" >,注釋<capabilities>部分,然后在命令行中運行aspnet_regbrowsers -i。以解決text/vnd.wap.wml問題。

<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>

  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"/>

 


免責聲明!

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



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