【问题标题】:Improve WCF service performance提高 WCF 服务性能
【发布时间】:2011-11-19 02:27:40
【问题描述】:

我的公司拥有一台具有 24 个内核和大量内存的服务器。操作系统是 Windows 2008 R2 SP1。我在这台服务器上部署了一个 WCF 应用程序,托管在 IIS 中。在同一台服务器上,我安装了一个多线程客户端,它尽可能频繁地调用 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。有没有人遇到过类似的问题?我搜索了几天的解决方案,但我还没有找到它:(

提前谢谢你!

【问题讨论】:

  • 是什么让你认为 CPU 使用率是制约因素?
  • 在“只有”八核的服务器上,我获得的性能几乎与我在帖子中提到的服务器上相同...
  • @schglurps 如果你在 8 和 24 上获得相同的性能,这几乎证明它与 CPU 无关

标签: c# wcf performance iis-7.5


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2011-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-18
    • 1970-01-01
    • 1970-01-01
    • 2014-10-08
    相关资源
    最近更新 更多