Article ID: 821268 - Last Review: July 28, 2009 - Revision: 11.0 Contention, poor performance, and deadlocks when you make Web service requests from ASP.NET applicationsOn This PageSYMPTOMSWhen 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 "hang") or take a very
long time to execute. If a deadlock is suspected, the worker process may be
recycled. You may receive the following messages in the application event log.
“System.InvalidOperationException:
There were not enough free threads in the ThreadPool object to complete the
operation.” “HttpException (0x80004005): Request timed
out.” CAUSEThis problem might occur because ASP.NET limits the number
of worker threads and completion port threads that a call can use to execute
requests. Typically, a call to 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. 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. RESOLUTIONTo resolve these problems, you can tune the following
parameters in your Machine.config file to best fit your situation:
maxWorkerThreads and maxIoThreadsASP.NET uses the following two configuration settings to limit the maximum number of worker threads and completion threads that are used:2*maxWorkerThreads minFreeThreads and minLocalRequestFreeThreadsASP.NET also contains the following configuration settings that determine how many worker threads and completion port threads must be available to start a remote request or a local request: (maxWorkerThreads*number of CPUs)-minFreeThreads Note The minFreeThreads parameter and the minLocalRequestFreeThreads parameter are not implicitly multiplied by the number of CPUs.minWorkerThreadsAs of ASP.NET 1.0 Service Pack 3 and ASP.NET 1.1, ASP.NET also contains the following configuration setting that determines how many worker threads may be made available immediately to service a remote request.maxconnectionThe maxconnection parameter determines how many connections can be made to a specific IP address. The parameter appears as follows:executionTimeoutASP.NET uses the following configuration setting to limit the request execution time:Note If you increase the value of the executionTimeout parameter, you may also have to modify the processModel responseDeadlockInterval parameter setting. RecommendationsThe settings that are recommended in this section may not work for all applications. However, the following additional information may help you to make the appropriate adjustments.If you are making one Web service call to a single IP address from each ASPX page, Microsoft recommends that you use the following configuration settings:
Note When you use this configuration, you can execute a maximum of 12 ASP.NET requests per CPU at the same time because 100-88=12. Therefore, at least 88*N worker threads and 88*N completion port threads are available for other uses (such as for the Web service callbacks). For example, you have a server with four processors and hyperthreading enabled. Based on these formulas, you would use the following values for the configuration settings that are mentioned in this article. Also, when you use this configuration, 12 connections are available per CPU per IP address for each AppDomain. Therefore, in the following scenario, very little contention occurs when requests are waiting for connections, and the ThreadPool is not exhausted:
STATUS This
behavior is by design. MORE INFORMATION If you are experiencing poor performance and contention on IIS 7.0 with ASP.NET, see the following Microsoft blogs: ASP.NET Thread Usage on IIS 7.0 and 6.0 http://blogs.msdn.com/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspx
(http://blogs.msdn.com/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspx)
ASP.net Hang in IIS 7.0http://blogs.msdn.com/webtopics/archive/2009/02/13/asp-net-hang-in-iis-7-0.aspx
(http://blogs.msdn.com/webtopics/archive/2009/02/13/asp-net-hang-in-iis-7-0.aspx)
REFERENCESFor more information, visit the following Microsoft
Developer Network (MSDN) Web site: http://msdn2.microsoft.com/en-us/library/ms998549.aspx
(http://msdn2.microsoft.com/en-us/library/ms998549.aspx)
| Article Translations
|
Back to the top
