04 June 2016

Supporting high HttpWebRequest volume in .NET application

If your .NET application is getting Timeouts while making huge number of HTTP web requests, before blaming on the supported NETWORK bandwidth between the client and server consider below points:

  • How many concurrent HTTP Web Requests are being allowed by .NET framework?
  • KeepAlive setting on HttpWebRequest

Let's get into more details:

Configuring Maximum Concurrent HTTP requests

By default your applicaiton running on .NET framework allowed to MAKE only certain number concurrent HTTP WEB requests. I think its around MAX of 2 to 4. You can easily increase this limit to safe number needed by application to support the load to be supported.

Below is the config section settings you need to have in your application / web config files.

     <add address="*" maxconnection="80"/>

Increase maxconnection to a number need by your application. But before releasing ensure you load test the same. You need to ensure it doesn't overload the HTTP server you are hitting. In case if your server not able to handle the requests, you still get exceptions (May be Server is too busy, etc).

Setting KeepAlive on HttpWebRequest

By setting KeepAlive = true on HttpWebRequest object, you will tell the mechanism to use the persistent HTTP connection between client and the server.

With persistent connection, the connection need not to be newly created and destroyed between each HTTP WEB request. But KeepAlive setting value may not always be considered if the PROXY between the client and server is not supporting the persistent connection and also when your HTTP WEB server has disabled PERSISTENT HTTP connections.

No comments:

Post a Comment