Note: This article requires existing knowledge of Web Services and .NET.
When you make calls to XML Web services from an ASP.NET application, you may experience contention, poor performance, and deadlocks. Clients may report that requests stop responding or takes a very long time to execute.
The problem might occur because ASP.NET limits the number of worker threads and completion port threads that a call can use to execute requests.
To resolve the issue we can modify the web.config file in the .NET project.
- Modify/add the parameters in the configuration file by adding the following attributes:
Follow these steps:
- Open the web.config file
- Look for the <system.web> element. Add processModel and httpRuntime elements and assign the following attributes:
<processModel maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50"/>
<httpRuntime minFreeThreads="704" minLocalRequestFreeThreads="608"/>
How does the parameter improve my webservice performance?
A web service uses one worker thread to execute the code that sends the request and one completion port thread to receive the callback from the Web service. However, if the request is redirected or requires authentication, the call may use as many as two worker and two completion port threads. Therefore, you can exhaust the managed ThreadPool when multiple Web service calls occur at the same time.
For example, suppose that the ThreadPool is limited to 10 worker threads, and all 10 worker threads are currently executing code that is waiting for a callback to execute. The callback can never execute because any work items that are queued to the ThreadPool are blocked until a thread becomes available.
3. In the web.config file look for the <system.net> element and add the maxconnection attribute.
<add address="|IP Address Here|" maxconnection="96"/>
Another potential source of contention is the maxconnection parameter that the System.Net namespace uses to limit the number of connections. Generally, this limit works as expected. However, if many applications try to make many requests to a single IP address at the same time, threads may have to wait for an available connection.