How to limit incoming http requests within IIS?

Viewed 479

Introduction

We have an ASP.NET v4.6.1 web application hosted within IIS v10.0 (or IIS Express for development purpose) in integrated mode - CLR ASP.NET v4.0.30319. Http requests which web application is processing are relatively resource heavy - couple of calls to internal services are made as well as some processing of result is being done. Some of them can took couple of seconds. To avoid exhaustion of physical resource we are blocking invidual http requests if a semaphore capacity is reached out (we are allowing N-number of concurrent requests, where N is finite number). This semaphore is introduced in a downstream.

Nevertheless there is no blocking in terms of processing newly incoming requests (although the semaphor is fully filled). Such a request is still handled in ASP.NET worker. In addition, such processing takes some resources and memory space. Before the request goes to the downstream where the semaphor is introduced, it takes some processing - new objects are created, parameters are binded into the models, action filter are used with some logic and so on.

Blocking in such a manner is not really efficient. So it occured to us that it would be ideal if the requests could be blocked (queued up) at the level of IIS itself. Thus if there is no free thread to handle to incoming HTTP request, the request would be added to the queue on the IIS and it would not forwarded to ASP.NET worker until a thread is free and ready to process another request.

I found that it could help us to set a parameter within aspnet.config, especially the number of current request per CPU.

Since we are mainly using IIS Express for developping purpose we have set the aspnet.config located on the following path:

%userprofile%\Documents\IISExpress\config\aspnet.config

<system.web> 
   <applicationPool maxConcurrentRequestsPerCPU="8 maxConcurrentThreadsPerCPU="0" requestQueueLimit="5000"/> 
</system.web>  

Unfortunately, the settings for these changes did not take effect. I tried to change also the machine.config on these paths:

  • C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config
  • C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config

Thanks to the performance monitor tool I have been monitoring the ASP.NET v4.0.30319 Requests Queued, Requests Current metrics. I did not spot any changes not even on application level.

We would like to set maximum parallel request to 96. Since we have 6 cores with hyperthreading (so in total we have 12 logical cores) we have set the maxConcurrentRequestsPerCPU to 8.

Please note:
I noticed that there is also another parameter to limit available concurrent connections. However, this is not the case we want to use, since by decreasing we are limiting other clients which they can get 503 http status error code.

How do I set up IIS properly to queue requests on a internal queue and not to proceed to the ASP.NET worker until a thread is free? Is that even possible?

Is there any mechanism how to block and queue up natively incoming request before coming to ASP.NET worker in case IIS is not capable to do that?

1 Answers

You could try with these options -

Queue Length property: This property will queue for maximum number of requests http requests that can be handled by the app pool.

https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.administration.applicationpool.queuelength?view=iis-dotnet

AppPool Advanced Settings

If you are interested to limit CPU utilization, You could use Limit(percent) option available under CPU.

Regarding your processing of calls, see if you could try using Parallel Options or async methods in your code to speed up your code execution.

PS: I have personally not made changes to Application pool properties to validate if it works.

Related