提高WCF服务性能

发布于 2024-12-16 19:48:42 字数 1741 浏览 0 评论 0原文

我的公司拥有一台 24 核和大量 RAM 的服务器。操作系统是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。有人遇到过类似的问题吗?我搜索了好几天的解决方案,但还没有找到:(

提前谢谢你!

My company owns a server with 24 cores and a lot a RAM inside. The OS is Windows 2008 R2 SP1. I deployed on this server a WCF application, hosted in IIS. On the same server I installed a multithreaded client which calls one of the WCF service, as often as possible. I encountered a bottleneck : all the cores on the server are used, but at a very low level, so the CPU consumption doesn't exceed 10 %. My WCF service is configured like this :

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

My service has also the following attributes : InstanceContextMode.Single and ConcurrencyMode.Multiple. Did anyone encounter a similar problem ? I searched the solution for days, but I didn't find it yet :(

Thank you in advance !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期以后 2024-12-23 19:48:42

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

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

I'm not sure how you're measuring the performance bottleneck but no matter how many client calls you generate, the service will only handle 200 calls at a time. The netTcpBinding is uses sessions so the throttle there is the maxConcurrentSessions="200" setting. You've configured the service as a multi-threaded singleton which is limited to 200 simultaneous calls by the maxConcurrentCalls="200" setting. The CPU load will also depend on how much work is performed during each call and whether it is IO bound or not. Review the serviceThrottling element documentation and try increasing both settings to see if your throughput improves.

If your sevice implementation allows, I would recommend you try configuring the service with InstanceContextMode.PerSession and ConcurrencyMode.Single to compare throughput with your current configuration. IIS 7x hosts WCF services using the Windows Process Activation Service (WAS). WAS is designed to handle concurrency. A singleton configuration negates the value of using WAS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文