【问题标题】:How to increase the number of parallel connections for a WCF service如何增加 WCF 服务的并行连接数
【发布时间】:2014-11-05 09:23:03
【问题描述】:

我正在调查我们的 Web 应用程序存在性能问题。它使用 4 层架构,带有 MVC4 webapp、WCF 数据服务和 SQLServer 作为 DB。 尽管有足够的可用资源,但数据服务并没有真正扩展请求。它似乎只并行回答 10-12 个请求并将所有其他请求排队。我想看到它同时回答 >100 个请求。

  1. 我尝试使用我找到的所有配置值 WCF 的这个主题:system.net -> connectionManagement -> add maxconnection=100 serviceBehavior -> serviceThrottling -> maxConcurrentCalls/Instances/Sessions=100。没有成功。
  2. 我尝试使用 httpBinding 以及我发现的 netTcpBinding 将参数 maxConnections 设置为 100。没有成功。
  3. 是 WCF 吗?我实现了一个简单的 sleep.aspx 网络表单,它有 1s 到 返回(使用 Thread.Sleep())。同样的结果,只有 10-12 个请求 在 1 秒内得到答复,进一步的请求将排队。
  4. 是 .Net 吗?我在测试机上安装了 ActiveState Perl 并 写了一个同样的小 Perl 脚本。相同的结果,10-12 直接回答请求,其他请求排队。
  5. 是 Windows 吗?我在 Linux 机器上安装了 Perl 脚本 阿帕奇。测试客户端在 Windows 下运行。在这个星座我 当我将 Apache 配置为具有尽可能多的响应时,在 1 秒内得到 100 个响应 服务器进程。
  6. IIS 也能够运行多个进程而不是多个 线程(网络花园)也是如此。啊,这种情况下IIS也回答100 并行请求。

所有这一切让我得出结论,单个 Windows 进程可能无法并行处理超过 10-12 个 TCP 连接。

这是真的吗?这可以在某处配置吗?

由于数据服务的设计,它不应该与多个进程一起运行,因为它使用需要与所有其他实例同步的对象缓存。

Google 似乎对此问题知之甚少。

环境:Windows Server 2008 R2/Windows Server 2012 R2、MVC4、WCF、.Net 4.5.1

汤米

【问题讨论】:

    标签: c# .net wcf windows-server


    【解决方案1】:
     <serviceBehaviors>
         <behavior name="defaultServiceBehavior">
              <serviceThrottling maxConcurrentCalls="100" 
                     maxConcurrentInstances="100" maxConcurrentSessions="100" />
         </behavior>
     </serviceBehaviors>
    

    以下是这些设置的摘要:

    maxConcurrentCalls: defines the maximum number of messages actively processed by all the service instances of a ServiceHost. The default value is 16. Calls in excess of the limit are queued.
    
    maxConcurrentInstances: defines the maximum number of service instances that can execute at the same time. The default value is Int32.MaxValue. Requests to create additional instances are queued and complete when a slot below the limit becomes available.
    maxConcurrentSessions: defines the maximum number of sessions that a ServiceHost instance can accept at one time. The default value is 10. The service will accept connections in excess of the limit, but only the channels below the limit are active (messages are read from the channel).
    

    【讨论】:

    • serviceBehaviors 是 WCF 配置选项,使用 webforms 甚至 perl 脚本可以看到相同的行为。更改这些设置没有效果,我无法增加并行度。
    【解决方案2】:

    你可以尝试几件事

    添加服务行为以最大限度地提高它可以处理的调用量

      <serviceBehaviors>
        <behavior name="StandardServiceBehavior">
          <serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="10000"/>
        </behavior>
     </serviceBehaviors>
    

    您是否尝试过在服务行为中使用并发模式?

    也许将服务行为设置为

    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]

    在此处查看此设置的作用的完整说明。

    http://msdn.microsoft.com/en-us/library/system.servicemodel.concurrencymode(v=vs.110).aspx

    您可能还想尝试为您的 wcf 服务添加一些日志记录,请参阅此链接

    http://msdn.microsoft.com/en-us/library/ms730064(v=vs.110).aspx

    它应该让您更深入地了解实际发生的情况以及是否存在任何错误。有时我也看到如果 maxconcurrentcalls 已被击中,它会将对服务的调用排队,这些显示为警告。

    【讨论】:

    • 一个windows进程可以处理超过10-12个连接。老实说,听起来您确实在达到 maxConcurrentCalls。
    • 感谢您的回复,我尝试使用 ConcurrencyMode 和 maxConcurrentCalls,但收效甚微。可以进一步降低并行性,但我无法增加它。
    猜你喜欢
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多