Optimizing WCF Web Service Performance


WCF services expose numerous configuration parameters that affect performance. This topic provides general guidance for setting optimal values for these configuration parameters to improve performance of WCF services.

Implement serviceThrottling behavior for backend WCF services. Service throttling allows you to even out the load on your backend WCF servers and to enforce resource allocation. serviceThrottling behavior for backend WCF services is configured by modifying the values for the maxConcurrentCalls, maxConcurrentSessions, and maxConcurrentInstances parameters in the config file for the WCF service. Set maxConcurrentCalls, maxConcurrentSessions, and maxConcurrentInstances to a value greater than 16 * the number of CPUs or CPU cores. For example, on a computer with 8 CPU cores, set maxConcurrentCalls, maxConcurrentSessions, and maxConcurrentInstances to a value greater than 128 (16 * 8 = 128) as follows:

maxConcurrentInstances="200" />

The NetTcpBinding.ListenBacklog property controls the maximum number of queued connection requests that can be pending for a Web service. The NetTcpBinding.MaxConnections property controls the maximum number of connections to be pooled for subsequent reuse on the client and the maximum number of connections allowed to be pending dispatch on the server. Each of these properties uses a default value of 10 which may be suboptimal, especially for document processing scenarios that require high throughput.

Consider increasing the default value of these properties for high-throughput, document-processing scenarios that use WCF services which implement the netTcpBinding binding class.

In the following example, both the listenBacklog and maxConnections parameters are set to a value of “200”.

   <binding name="netTcpBinding"
         maxNameTableCharCount="16384" />
         enabled="false" />
      <security mode="None">
         <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
         <message clientCredentialType="Windows" />

For more information about the NetTcpBinding.ListenBacklog property, see NetTcpBinding.ListenBacklog Property (http://go.microsoft.com/fwlink/?LinkId=157752) on MSDN.

For more information about the NetTcpBinding.MaxConnections property, see NetTcpBinding.MaxConnections Property (http://go.microsoft.com/fwlink/?LinkID=157751) on MSDN.

By default, several ASP.NET httpModules are defined in the Request Pipeline in IIS 6.0 and in the Classic or Integrated Pipeline in IIS 7.5/7.0. These components intercept and process all incoming requests. The default modules are defined in the web.config file contained in the %windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG folder for 32-bit ASP.NET applications and in the %windir%\Microsoft.NET\Framework64\v2.0.50727\CONFIG folder for 64-bit ASP.NET applications, as shown by the following snippet.

<add name="OutputCache" type="System.Web.Caching.OutputCacheModule"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
<add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule"/>
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule"/>
<add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule"/>
<add name="RoleManager" type="System.Web.Security.RoleManagerModule"/>
<add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule"/>
<add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule"/>
<add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule"/>
<add name="Profile" type="System.Web.Profile.ProfileModule"/>
<add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule, System.Web.Mobile, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

In most scenarios it is not necessary to load all of these modules. Therefore, it is possible to improve performance by eliminating the following httpModules when running WCF Web services:

  • Session

  • WindowsAuthentication

  • FormsAuthentication

  • PassportAuthentication

  • RoleManager

  • AnonymousIdentification

  • Profile

The WCF Module/Handler Registration Tool is available for download at http://go.microsoft.com/fwlink/?LinkId=157593 (http://go.microsoft.com/fwlink/?LinkId=157593). This utility can be used to install, list, or configure the following WCF modules:

  • WCF Synchronous HTTP module and handler

  • WCF Asynchronous HTTP module and handler

  • WCF HTTP module and handler

For more information about using the asynchronous WCF HTTP modules/handlers to improve the scalability of IIS 7.5/7.0 hosted WCF services, see Wenlong Dong’s blog Orcas SP1 Improvement: Asynchronous WCF HTTP Module/Handler for IIS7 for Better Server Scalability (http://go.microsoft.com/fwlink/?LinkId=157428).