Improving throughput of your Microsoft stack web app
The flow of a web request (from IIS inwards)
The request is still handed over to ASP.NET on an IIS I/O thread. And ASP.NET immediately posts the request to the CLR Threadpool and returns pending.
If your application sees a large number of concurrent requests at start-up or has a bursty load, where concurrency increases suddenly, you will need to make the application asynchronous because the CLR ThreadPool does not respond well to these loads. The CLR ThreadPool injects new threads at a rate of about 2 per second. This is true for all versions of the CLR (v1.0 thru v4.0) at the time of this writing.
Pre – ASP.NET 4.0 and IIS7.5
The registry key , MaxConcurrentRequestsPerCPU in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\2.0.50727
By default, MaxConcurrentRequestsPerCPU does not exist and the number of requests per CPU is limited to 12.
Post ASP.NET 4.0 and IIS 7.5
In v4.0, the ASP.NET team has changed the default for MaxConcurrentRequestsPerCPU to 5000 – which will allow plenty of async requests to execute concurrently.
Recommendation 1 – Upgrade to asp.net 4.5 and IIS 7.5
Windows Server
.NET 4.5 requires Windows Server 2008 or above (2003 Server hosts cannot avail of the 5000 concurrent request handling capabilities of .NET 4.5)
IIS
IIS Tuner – While originally intended for IIS 6.0 tweaking, it works for IIS 7.X as well. The main setting in IIS that you want to tweak is the IIS Queue size. Set this to the max number of concurrent requests you are anticipating. Default is 1000. We set it to 5000 for a high volume eCommerce web app. Now, corresponding to IIS’s incoming 5000 requests, ASP.NET would also need to handle the same number concurrently – and be able to pass them along to WCF (those that are MEANT for WCF). In our case, every request that came into ASP.NET (MVC) was calling a WCF Service – so there was a 1-1 mapping of IIS Requests—>ASP.NET Requests—>WCF Requests.
ASP.NET
Runtime 4.5 or above – default is 5000 concurrent connections to an ASP.NET 4.5 application .
NOTE: Simply installing the 4.5 runtime and changing your web.config to use framework version 4.5 will not be enough. You effectively have to upgrade every library in your project to use 4.5 – and then re-deploy your project. See this post for upgrading your 4.0 web app to 4.5.
Runtime 4.0
- Maximum concurrent connections to an ASP.net 4 Web Application can be set with ApplicationPool’s maxConcurrentRequestsPerCPU property:
<system.web> <applicationPool maxConcurrentRequestsPerCPU="20000" /> </system.web>
WCF
In the Services layer’s (WCF Layer’s) web.config, there are a few settings to concern yourself with.
maxConcurrentCalls=”500″ maxConcurrentInstances=”500″
Appendix A – List of Tools
Lean Sentry – To analyze asp.net and IIS hangs – and also real time monitoring of your website.
IIS Tuner – to tweak IIS 6.X and above settings
Leave a Reply