提高WCF服务性能

时间:2011-11-18 17:06:51

标签: c# wcf performance iis-7.5

我的公司拥有一个24核的服务器,里面有很多RAM。操作系统是Windows 2008 R2 SP1。我在此服务器上部署了一个托管在IIS中的WCF应用程序。在同一台服务器上,我安装了一个多线程客户端,尽可能多地调用其中一个WCF服务。我遇到了一个瓶颈:服务器上的所有核心都被使用,但是处于非常低的水平,因此CPU消耗不超过10%。我的WCF服务配置如下:

  <system.serviceModel>
<services>
  <service behaviorConfiguration="myBehavior" name="...">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="myBinding" bindingNamespace="..." contract="..."/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="myBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="200" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <netTcpBinding>
    <binding name="myBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="2147483647" maxReceivedMessageSize="2147483647" portSharingEnabled="false" transactionFlow="false" listenBacklog="2147483647">
      <security mode="None">
        <message clientCredentialType="None"/>
        <transport protectionLevel="None" clientCredentialType="None"/>
      </security>
      <reliableSession enabled="false"/>
      <readerQuotas maxDepth="64" maxStringContentLength="204800" maxArrayLength="204800" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
    </binding>
  </netTcpBinding>
</bindings>

我的服务还具有以下属性:InstanceContextMode.Single和ConcurrencyMode.Multiple。有没有人遇到类似的问题?我搜索了解决方案好几天了,但我还没找到它:(

提前谢谢!

1 个答案:

答案 0 :(得分:4)

我不确定您是如何衡量性能瓶颈的,但无论您生成多少客户端呼叫,该服务一次只能处理200个呼叫。 netTcpBinding使用会话,因此限制是maxConcurrentSessions="200"设置。您已将服务配置为多线程单例,maxConcurrentCalls="200"设置限制为200个同时调用。 CPU负载还取决于每次调用期间执行的工作量以及是否为IO绑定。查看serviceThrottling element文档并尝试增加两个设置,以查看吞吐量是否有所改善。

如果您的服务实现允许,我建议您尝试使用InstanceContextMode.PerSessionConcurrencyMode.Single配置服务,以将吞吐量与当前配置进行比较。 IIS 7x使用Windows进程激活服务(WAS)托管WCF服务。 WAS旨在处理并发性。单例配置否定了使用WAS的价值。

相关问题