Click here to Skip to main content
15,906,467 members
Articles / Web Development / ASP.NET

Quick Ways to Boost Performance and Scalability of ASP.NET, WCF and Desktop Clients

Rate me:
Please Sign up or sign in to vote.
4.89/5 (44 votes)
11 Jun 2011CPOL9 min read 246.8K   152   21
There are some simple configuration changes that you can make on machine.config and IIS to give your web applications significant performance boost. These are simple harmless changes but make a lot of difference in terms of scalability.


There are some simple configuration changes that you can make on machine.config and IIS to give your web applications significant performance boost. These are simple harmless changes but make a lot of difference in terms of scalability. By tweaking changes, you can increase the number of parallel calls that can be made from the services hosted on your servers as well as on desktop computers and thus increase scalability. By changing WCF throttling config, you can increase the number of simultaneous calls WCF can accept and thus make most use of your hardware power. By changing ASP.NET process model, you can increase the number of concurrent requests that can be served by your website. And finally, by turning on IIS caching and dynamic compression, you can dramatically increase the page download speed on browsers and overall responsiveness of your applications. Changes

By default, has two concurrent connections per IP allowed. This means on a webserver, if it’s calling WCF service on another server or making any outbound call to a particular server, it will only be able to make two concurrent calls. When you have a distributed application and your webservers need to make frequent service calls to another server, this becomes the greatest bottleneck.


Similarly, if you have a desktop application which is trying to make several webservice calls to the server, the setting on the client computer’s machine.config will only allow two concurrent calls to your webserver. If your app makes many concurrent calls to your webserver, then this becomes the main bottleneck. No matter how fast your client app and server are, the two concurrent limit will kill it.


In order to overcome the limit, you have to change the configuration either in the web.config or at machine.config. For desktop applications, you need to apply it on app.Config.

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

This gives all IP addresses 100 concurrent connections limit. You might want to be specific and specify some fixed IP address or domain name. If you are doing this on desktop apps, 100 might be overkill. Better go for a moderate value to prevent accidental flood of calls going to webserver and bringing it down.

WCF Throttling

Just like and system.web default settings that more or less prevent you from making highly scalable applications, the WCF default configuration is very stingy. It allows only 16 concurrent calls per service by default. Moreover, if you are using wsHttpBinding and using sessions, then only 10 concurrent sessions are allowed. Too low for popular applications nowadays.

There’s no better summary of all the WCF settings than this blog post. I will highlight the most common settings that you should always change:

  <behavior name="defaultServiceBehavior">
     <serviceThrottling maxConcurrentCalls="100" 
	maxConcurrentInstances="100" maxConcurrentSessions="100" />   

Here’s a summary of these settings:

  • maxConcurrentCalls: defines the maximum number of messages actively processed by all the service instances of a ServiceHost. The default value is 16. Calls in excess of the limit are queued.
  • maxConcurrentInstances: defines the maximum number of service instances that can execute at the same time. The default value is Int32.MaxValue. Requests to create additional instances are queued and complete when a slot below the limit becomes available.
  • maxConcurrentSessions: defines the maximum number of sessions that a ServiceHost instance can accept at one time. The default value is 10. The service will accept connections in excess of the limit, but only the channels below the limit are active (messages are read from the channel).

Also make sure your services have InstancePerContext.PerCall set. This ensures each request is handled by a new instance of the service on a new thread.

If you are hosting your WCF services via ASP.NET (e.g. using WCF REST Starter Kit), then you are further bogged down by the ASP.NET process model changes and you need to beef that up as well.

ASP.NET Process Model Changes

Process Model configuration defines some process level properties like how many number of threads ASP.NET uses, how long it blocks a thread before timing out, how many requests to keep waiting for IO works to complete and so on. The default is in most cases too limiting. Nowadays, hardware has become quite cheap and dual core with gigabyte RAM servers have become a common choice. So, the process model configuration can be tweaked to make ASP.NET process consume more system resources and gain better scalability from each server.

A regular ASP.NET installation will create machine.config with the following configuration:

    <processModel autoConfig="true" />  

You need to tweak this auto configuration and use some specific values for different attributes in order to customize the way ASP.NET worker process works. For example:


Here all the values are default values except for the following ones:

  • maxWorkerThreads - This is default to 20 per process. On a dual core computer, there'll be 40 threads allocated for ASP.NET. This means at a time ASP.NET can process 40 requests in parallel on a dual core server. I have increased it to 100 in order to give ASP.NET more threads per process. If you have an application which is not that CPU intensive and can easily take in more requests per second, then you can increase this value. Especially if your Web application uses a lot of Web service calls or downloads/uploads a lot of data which does not put pressure on the CPU. When ASP.NET runs out of worker threads, it stops processing more requests that come in. Requests get into a queue and keep waiting until a worker thread is freed. This generally happens when a site starts receiving much more hits than you originally planned. In that case, if you have CPU to spare, increase the worker threads count per process.
  • maxIOThreads - This is default to 20 per process. On a dual core computer, there'll be 40 threads allocated for ASP.NET for I/O operations. This means at a time ASP.NET can process 40 I/O requests in parallel on a dual core server. I/O requests can be file read/write, database operations, web service calls, HTTP requests generated from within the Web application and so on. So, you can set this to 100 if your server has enough system resource to do more of these I/O requests. Especially when your Web application downloads/uploads data, it calls many external webservices in parallel.
  • minWorkerThreads - When a number of free ASP.NET worker threads fall below this number, ASP.NET starts putting incoming requests into a queue. So, you can set this value to a low number in order to increase the number of concurrent requests. However, do not set this to a very low number because Web application code might need to do some background processing and parallel processing for which it will need some free worker threads.
  • minIOThreads - Same as minWorkerThreads but this is for the I/O threads. However, you can set this to a lower value than minWorkerThreads because there's no issue of parallel processing in case of I/O threads.
  • memoryLimit - Specifies the maximum allowed memory size, as a percentage of total system memory, that the worker process can consume before ASP.NET launches a new process and reassigns existing requests. If you have only your Web application running in a dedicated box and there's no other process that needs RAM, you can set a high value like 80. However, if you have a leaky application that continuously leaks memory, then it's better to set it to a lower value so that the leaky process is recycled pretty soon before it becomes a memory hog and thus keep your site healthy. Especially when you are using COM components and leaking memory. However, this is a temporary solution, you of course need to fix the leak.

I have a highly popular article on more ASP.NET optimization techniques. Please read that as well if you are building a rich ASP.NET application with many AJAX goodies.

Turn on IIS Caching and Dynamic Compression

You can enable IIS compression for static and dynamic content. The dynamic content compression will affect output from aspx and WCF services.


If you find the Enable Dynamic Content Compression option disabled, then you need to go to “Add or Remote Features” from Windows start menu and then enable the IIS Dynamic Compression from IIS features.

You might have to enable the compression first at server level and then at site level.

Monitor Your Server for Performance Issues

You can use the Windows Performance Monitor to monitor some key performance counters in order to identify performance bottlenecks. For example, the following counters should be monitored for ASP.NET web application hosting WCF services.


In order to enable WCF Performance counters, you need to put this in web.config:

   <diagnostics performanceCounters="All" />

This will tell WCF to log values in the performance counter so that you can see them from the Performance Monitor.

Things are Improved in WCF 4

In WCF 4, the default settings are much relaxed and carefully calculated to make best balance of CPU and threads. Here's what the default configuration is according to WCF team member's blog post:

In WCF 4, we have revised the default values of these settings so that people don’t have to change the defaults in most cases. Here are the main changes:

  • MaxConcurrentSessions: default is 100 * ProcessorCount
  • MaxConcurrentCalls: default is 16 * ProcessorCount
  • MaxConcurrentInstances: default is the total of the above two, which follows the same pattern as before.

Yes, we use the multiplier “ProcessorCount” for the settings. So on a 4-proc server, you would get the default of MaxConcurrentCalls as 16 * 4 = 64. The basic consideration is that, when you write a WCF service and you use the default settings, the service can be deployed to any system from low-end one-proc server to high-end such as 24-way server without having to change the settings. So we use the CPU count as the multiplier.

We also bumped up the value for MaxConcurrentSessions from 10 to 100. Based on customer’s feedback, this change fits the need for most applications.

Please note, these changes are for the default settings only. If you explicitly set these settings in either configuration or in code, the system would use the settings that you provided. No “ProcessCount” multiplier would be applied.


The above performance tweaks are so common in web application nowadays that without them, you just can’t build an application that can serve thousands of users. It’s surprising that the default configuration is so stingy that it makes companies spend hundreds of dollars investigating performance and scalability bottlenecks that can easily be resolved by the above tweaks.

Image 5


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

Comments and Discussions

QuestionVery informative... Pin
Suvabrata Roy8-Sep-15 1:40
professionalSuvabrata Roy8-Sep-15 1:40 
QuestionIs it applies to IIS 7.0? Pin
Suhas Bothe8-Jul-15 22:54
Suhas Bothe8-Jul-15 22:54 
GeneralMy vote 5 Pin
Aarti Meswania26-Mar-14 18:49
Aarti Meswania26-Mar-14 18:49 
QuestionHow many concurrent requests a normal based website can handle Pin
Tridip Bhattacharjee30-Aug-13 2:39
professionalTridip Bhattacharjee30-Aug-13 2:39 
GeneralMy vote of 5 Pin
buddy.james1-Jan-12 5:18
buddy.james1-Jan-12 5:18 
QuestionWCF Instances limited to 10 even using .Net 4.0 & IIS 7.5 Pin
biztalkers.com24-Oct-11 23:28
biztalkers.com24-Oct-11 23:28 
Questionnice article! Pin
Nelly S17-Jul-11 19:16
Nelly S17-Jul-11 19:16 
GeneralMy vote of 5 Pin
rht34127-Jan-11 14:08
rht34127-Jan-11 14:08 
General5! Pin
Al-Farooque Shubho20-Jan-11 1:56
Al-Farooque Shubho20-Jan-11 1:56 
GeneralMy vote of 5 Pin
prasad0222-Dec-10 4:39
prasad0222-Dec-10 4:39 
Generalnice one Pin
Pranay Rana14-Dec-10 21:07
professionalPranay Rana14-Dec-10 21:07 
GeneralMy vote of 5 Pin
Ahsan Murshed6-Dec-10 20:00
Ahsan Murshed6-Dec-10 20:00 
GeneralThoughts Pin
PIEBALDconsult6-Dec-10 12:18
mvePIEBALDconsult6-Dec-10 12:18 
GeneralRe: Thoughts Pin
Omar Al Zabir6-Dec-10 23:47
Omar Al Zabir6-Dec-10 23:47 
GeneralThank you!! Pin
SleepyCrat6-Dec-10 11:16
SleepyCrat6-Dec-10 11:16 
GeneralWCF Throttling limits increased for .NET 4 Pin
Carel Lotz6-Dec-10 6:46
Carel Lotz6-Dec-10 6:46 
GeneralMy vote of 5 Pin
Forhad6-Dec-10 6:22
Forhad6-Dec-10 6:22 
GeneralThanks for the tips, one correction though... Pin
Pete Souza IV6-Dec-10 4:43
professionalPete Souza IV6-Dec-10 4:43 
GeneralGreate article Pin
EhsanShemirani5-Dec-10 23:25
EhsanShemirani5-Dec-10 23:25 
GeneralMy vote of 5 Pin
thatraja5-Dec-10 17:52
professionalthatraja5-Dec-10 17:52 
GeneralMy vote of 5 Pin
Nicholas Butler5-Dec-10 10:17
sitebuilderNicholas Butler5-Dec-10 10:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.