Wednesday, December 07, 2005

Tuning ASP.NET thread settings for optimum performance

To get an optimum performance out of ASP.NET Web Application you may need to change the following settings in machine.config. The following text has been reproduced from MSDN article on ASP.NET preformance optimizations

maxconnection. If your application makes calls to a remote Web service and the requests are waiting for the call to complete, you can increase the CPU utilization and your application performance by changing the maxconnection attribute.

maxWorkerThreads and maxIoThreads. These attributes define the maximum number of worker and I/O threads that the ASP.NET worker process is allowed to create. These values do not reflect the actual number of threads that are created by the worker process. The maximum value for these attributes is 100 per processor.

minFreeThreads. This attribute defines the number of threads that can be used for work other than processing incoming requests to the worker process. This attribute prevents the ASP.NET process from using a thread from the thread pool to handle a new HTTP request if this would mean that the free thread count drops below this limit. The attribute is specified on the element and has a default value of 8.

You can use this attribute to help prevent deadlocks by ensuring that a thread is available to handle callbacks from pending asynchronous requests. A deadlock can occur if all of the threads in the thread pool are currently in use handling incoming HTTP requests, and one or more of those requests are waiting for asynchronous callbacks. In this situation, there are no available threads to service the callback. You can set minFreeThreads to ensure that some free threads are available to process the callbacks.

  • maxconnection = 24 (threads used to make remote web service calls)
  • minFreeThreads = 176 (threads kept reserved for serving non-request calls)
  • minLocalRequestFreeThreads = 152
  • maxWorkerThreads = 100 (Maximum number of worker threads per CPU in the thread pool)
  • maxIoThreads = 100 (Maximum number of IO threads per CPU in the thread pool)

No of threads for processing incoming requests : (#CPU * maxWorkerThreads) – (#CPU * minFreeThreads)