共用方式為


最佳化 WCF Web 服務效能

WCF 服務會公開許多會影響效能的組態參數。 本主題提供設定這些組態參數最佳值的一般指引,以改善 WCF 服務的效能。

實作後端 WCF 服務的 serviceThrottling 行為

實作後端 WCF 服務的 serviceThrottling 行為。 服務節流可讓您甚至卸載後端 WCF 伺服器上的負載,並強制執行資源配置。 已設定後端 WCF 服務的 serviceThrottling 行為,方法是修改 WCF 服務的組態檔中 maxConcurrentCallsmaxConcurrentSessionsmaxConcurrentInstances 參數的值。 將 maxConcurrentCallsmaxConcurrentSessionsmaxConcurrentInstances 設定為大於 16 * CPU 核心數目的值。 例如,在具有 8 個 CPU 核心的電腦上,將 maxConcurrentCallsmaxConcurrentSessionsmaxConcurrentInstances 設定為大於 128 (16 * 8 = 128) 的值,如下所示:

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

在後端 WCF 服務 web.config 檔案中增加 NetTcpBinding.ListenBacklog 和 NetTcpBinding.MaxConnections 屬性的預設值

NetTcpBinding.ListenBacklog屬性可控制 Web 服務可擱置的佇列連線要求數目上限。 NetTcpBinding.MaxConnections屬性會控制要共用的連線數目上限,以供用戶端上後續重複使用,以及允許在伺服器上擱置分派的連線數目上限。 每一個屬性都會使用預設值 10,可能是次佳,特別是針對需要高輸送量的檔處理案例。

請考慮針對使用 WCF 服務實作 netTcpBinding 系結類別的高輸送量檔處理案例增加這些屬性的預設值。

在下列範例中, listenBacklogmaxConnections 參數都會設定為 「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>

如需 NetTcpBinding.ListenBacklog 屬性的詳細資訊,請參閱 NetTcpBinding.ListenBacklog 屬性

如需 NetTcpBinding.MaxConnections 屬性的詳細資訊,請參閱 NetTcpBinding.MaxConnections 屬性

消除執行 WCF Web 服務所需的 ASP.NET HTTPModules

根據預設,在 IIS 6.0 的要求管線和 IIS 7.5/7.0 的傳統或整合式管線中定義數個 ASP.NET HTTPModules。 這些元件會攔截並處理所有傳入的要求。 預設模組定義 web.config 于 %windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG 資料夾中的 %windir%\Microsoft.NET\Framework64\v2.0.50727\CONFIG 資料夾中,適用于 ASP.NET 32 位 ASP.NET 應用程式和 %windir%\Microsoft.NET\Framework64\v2.0.50727\CONFIG 資料夾,如下列程式碼片段所示。

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

在大部分情況下,不需要載入所有這些模組。 因此,在執行 WCF Web 服務時,可以排除下列 HTTPModules 來改善效能:

  • 工作階段

  • WindowsAuthentication

  • FormsAuthentication

  • PassportAuthentication

  • RoleManager

  • AnonymousIdentification

  • 設定檔

如需使用非同步 WCF HTTP 模組/處理常式來改善 IIS 7.5/7.0 託管 WCF 服務延展性的詳細資訊,請參閱 Wenlong Framework 的部落格 Orcas SP1 改進:IIS7 的非同步 WCF HTTP 模組/處理常式,以提升伺服器延展性

另請參閱

最佳化 BizTalk Server WCF 配接器效能