問題描述
從 IIS 6 升級到 8.5:增加並發請求 (Upgrading from IIS 6 to 8.5: increased concurrent requests)
我們將 Web 服務器從 Windows Server 2003 升級到了 Windows Server 2012 R2。有問題的 Web 應用程序針對 ASP.NET 4.0 運行。Web 應用程序又與第三方 Web API 通信。
升級後不久,Web API 延遲增加,進而導致明顯的超時。我懷疑在 IIS 8.5 上,允許的並發請求數增加,導致 Web API 無法處理的吞吐量增加。但是:
- IIS 6 不限制並發請求的數量。幫助文件內容如下:您可以將 Internet 信息服務 (IIS) 配置為允許無限數量的並發連接,或限制它為此網站接受的連接數量。我們目前將此設置為無限制。
- IIS 6 和 IIS 8.5 都使用 ASP.NET 4,它還可以限制並發請求的數量。兩個 IIS 版本都在 machine.config 文件中設置為自動配置;由於兩台服務器具有相同的處理器和 RAM 配置,它們應該使用相同的設置。
當我們回滾升級時,延遲很快就下降了。不太可能是巧合,所以在其他一切都保持不變的情況下,Windows 2012 R2 或 IIS 8.5 一定有一些內在的東西會影響 Web API。第 3 方 Web API 開發人員確認他們的空間沒有發生任何變化,不幸的是,我無法收集到任何其他信息。
我檢查了 IIS 6 和 8.5 的日誌:每秒、每分鐘和每小時的平均(和中值)請求表明在 IIS 8.5 上處理的請求更多(我使用 Log Parser Studio 分析日誌)。但是,沒有任何跡象表明應該如此。有沒有人有任何見解或建議?如果有控制這一點的設置,那麼現在我希望 Web 應用程序在 Windows Server 2003 和 2012 R2 上表現相同。
參考解法
方法 1:
Since each new request is processed on a new worker thread from the thread pool, I queried the thread pool limits to verify that the auto‑configured settings match (aspx
file):
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Threading" %>
<html>
<body>
<div>
<%
int workers;
int io;
ThreadPool.GetMaxThreads(out workers, out io);
%>
The maximum number of worker threads is <%=workers.ToString()%> and
the maximum number of IO threads is <%=io.ToString()%>
</div>
</body>
</html>
The results are as follows (the virtual machine had 2 cores):
- On Windows Sever 2003, running IIS 6: 200 worker, and 200 I/O thread limit
- On Windows Server 2012 R2, running IIS 8.5: 32767 worker, and 1000 I/O thread limit
This implies that the newer setup is able to handle more requests concurrently.