Muokkaa

Jaa


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

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:

<serviceThrottling
maxConcurrentCalls="200"
maxConcurrentSessions="200"
maxConcurrentInstances="200" />

Increase the default values for the NetTcpBinding.ListenBacklog and NetTcpBinding.MaxConnections properties in the backend WCF service web.config file

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”.

<netTcpBinding>
   <binding name="netTcpBinding"
      closeTimeout="00:10:00"
      openTimeout="00:10:00"
      receiveTimeout="00:10:00"
      sendTimeout="00:10:00"
      transactionFlow="false"
      transferMode="Buffered"
      transactionProtocol="OleTransactions"
      hostNameComparisonMode="StrongWildcard"
      listenBacklog="200"
      maxBufferPoolSize="1048576"
      maxBufferSize="10485760"
      maxConnections="200"
      maxReceivedMessageSize="10485760">
      <readerQuotas
         maxDepth="32"
         maxStringContentLength="8192"
         maxArrayLength="16384"
         maxBytesPerRead="4096"
         maxNameTableCharCount="16384" />
      <reliableSession
         ordered="true"
         inactivityTimeout="00:10:00"
         enabled="false" />
      <security mode="None">
         <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
         <message clientCredentialType="Windows" />
      </security>
   </binding>
</netTcpBinding>

For more information about the NetTcpBinding.ListenBacklog property, see NetTcpBinding.ListenBacklog Property.

For more information about the NetTcpBinding.MaxConnections property, see NetTcpBinding.MaxConnections Property.

Eliminate ASP.NET httpModules that are not required to run WCF Web services

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.

<httpModules>
<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=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</httpModules>

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

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.

See Also

Optimizing BizTalk Server WCF Adapter Performance