Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

IIS 效能優化八大實戰技巧:Keep-Alive、停用記錄、應用程式集區、快取、壓縮、CPU、偵錯、CGI

編輯:系統常見問題解答

IIS 5.0/6.0/7.x/8.x/10.0 通用八大效能調校動作,實測可提升 20~40% 輸送量:

  1. 啟用 HTTP Keep-Alive (預設開啟,確認未被關閉)
    IIS 管理員 → 網站 → 進階設定 → 「啟用 HTTP Keep-Alive」= True
    效益:+15~20% RPS,減少 TCP 三向交握開銷。
  2. 停用/精簡 W3C 記錄
    生產環境僅記錄錯誤/效能指標,或改用 ETW/EventSource 結構化日誌。
    效益:+5~8% RPS,減少磁碟 I/O 競爭。
  3. 使用 In-Process (低隔離) 應用程式集區
    僅受信任、相容的應用程式;高風險/舊版應用才用隔離 (高隔離)。
    效益:避免 -20% RPS (跨進程編組開銷)。
  4. 擴大快取記憶體與靜態內容快取
    <system.webServer><caching enabled="true" maxCacheSize="1000" /></system.webServer>
    <staticContent><clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" /></staticContent>
    效益:ASP/ASP.NET 靜態/動態內容命中率提升,降低 CPU。
  5. 移除 CGI、改用 FastCGI / ASP.NET Core / Node.js / Go
    CGI 每請求建立進程,極度低效。
    效益:+50~300% RPS (視應用複雜度)。
  6. 增加 CPU 核心 / 啟用 NUMA 感知
    實體核心 > 超執行緒;aspnet.config 設定 <processModel enable="true" maxWorkerThreads="100" maxIoThreads="100" /> (舊版)。
    效益:線性擴展 (至記憶體/鎖競爭瓶頸)。
  7. 關閉 ASP/ASP.NET 偵錯旗標
    <compilation debug="false" />、<httpRuntime fcnMode="Disabled" />、移除 trace.axd。
    效益:+10~30% RPS,減少符號表、堆疊追蹤開銷。
  8. 啟用靜態/動態內容 HTTP 壓縮 (Gzip/Deflate/Brotli)
    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
    <scheme name="br" dll="%Windir%\system32\inetsrv\brotli.dll" /> (Win 10/Server 2019+)
    靜態類型:js/css/json/svg/woff2/ico/html/xml/txt
    動態類型:application/json, text/html, application/xml
    效益:傳輸量 -60~80%,頻寬節省、首屏載入加速。

驗證清單

# 1. Keep-Alive
curl -I -H "Connection: keep-alive" https://example.com/ | grep -i "connection: keep-alive"

# 2. 壓縮
curl -I -H "Accept-Encoding: gzip, br" https://example.com/style.css | grep -i "content-encoding"

# 3. 快取標頭
curl -I https://example.com/script.js | grep -i "cache-control"

# 4. 偵錯旗標
grep -r "debug=\"true\"" C:\inetpub\wwwroot\web.config

依序套用、驗證、負載測試 (wrk/k6/JMeter),即可獲得穩定高效的 IIS 服務。

Copyright © Windows教程網 All Rights Reserved