简体   繁体   English

如何增加WCF服务的并行连接数

[英]How to increase the number of parallel connections for a WCF service

Our web application has performance problems which I am investigating. 我们的Web应用程序存在我正在调查的性能问题。 It uses a 4-tier architecture with a MVC4 webapp, WCF data service and SQLServer as DB. 它使用具有MVC4 Web应用程序,WCF数据服务和SQLServer作为DB的4层体系结构。 The data service does not really scale the requests although there are enough resources available. 尽管有足够的可用资源,但是数据服务并没有真正扩展请求。 It seems that it only answers 10-12 requests in parallel and queues all others. 似乎它只能并行回答10-12个请求,并将所有其他请求排队。 I would like to see that it answers >100 requests simultaneously. 我希望看到它可以同时回答100多个请求。

  1. I tried to play around with all configuration values I found for this topic for WCF: system.net -> connectionManagement -> add maxconnection=100 serviceBehavior -> serviceThrottling -> maxConcurrentCalls/Instances/Sessions=100. 我尝试使用针对该主题为WCF找到的所有配置值:system.net-> connectionManagement->添加maxconnection = 100 serviceBehavior-> serviceThrottling-> maxConcurrentCalls / Instances / Sessions = 100。 No success. 没有成功
  2. I tried to use httpBinding as well as netTcpBinding where I found the parameter maxConnections and set it to 100. No success. 我尝试使用httpBinding和netTcpBinding,在其中我找到了参数maxConnections并将其设置为100。没有成功。
  3. Is it WCF? 是WCF吗? I implemented a simple sleep.aspx webform that has 1s to return (using Thread.Sleep()). 我实现了一个简单的sleep.aspx Web表单,该表单返回1(使用Thread.Sleep())。 Same Result, only 10-12 Requests are answered within 1s, further requests are queued. 结果相同,在1s内仅响应10-12个请求,其他请求排队。
  4. Is it .Net? 是.Net吗? I installed ActiveState Perl on the testmachine and wrote a little Perl script which does the same. 我在测试机上安装了ActiveState Perl,并编写了一个相同的Perl脚本。 Same Result, 10-12 Requests are answered directly, others are queued. 结果相同,10-12个请求被直接回答,其他被排队。
  5. Is it Windows? 是Windows吗? I installed the Perl script on a Linux machine with Apache. 我在装有Apache的Linux机器上安装了Perl脚本。 The test client runs under Windows. 测试客户端在Windows下运行。 In this constellation I get 100 responses within 1s when I configure Apache to have as many server processes. 在此构架中,将Apache配置为具有尽可能多的服务器进程时,我会在1秒钟内收到100个响应。
  6. IIS is also able to run with multiple processes instead of multiple threads (Web garden) as well. IIS还可以在多个进程而不是多个线程(Web花园)中运行。 Ah, in this case, IIS also answers 100 requests in parallel. 嗯,在这种情况下,IIS还会并行回答100个请求。

All this brings me to the conclusion that a single Windows process might not be able to handle more than 10-12 TCP connection in parallel. 所有这些使我得出的结论是,单个Windows进程可能无法并行处理超过10-12个TCP连接。

Is this the truth? 这是事实吗? Can this be configured somewhere? 可以在某个地方配置它吗?

Due to the design of the data service it should not run with multiple processes because it uses an object cache which needs to be synchronized with all other instances. 由于数据服务的设计,它不应与多个进程一起运行,因为它使用的对象缓存需要与所有其他实例同步。

Google seems not to know much about this issue. Google似乎对这个问题不太了解。

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

Thomy omy

 <serviceBehaviors>
     <behavior name="defaultServiceBehavior">
          <serviceThrottling maxConcurrentCalls="100" 
                 maxConcurrentInstances="100" maxConcurrentSessions="100" />
     </behavior>
 </serviceBehaviors>

Here's a summary of these settings: 以下是这些设置的摘要:

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

There are several things you can try 您可以尝试几种方法

Add a service behaviour in to max out the amount of calls it can handle 添加服务行为以最大程度地处理服务数量

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

Have you tried playing around with the Concurrency mode in the service behaviour? 您是否尝试过在服务行为中使用并发模式?

maybe setting the service behaviour to 也许将服务行为设置为

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]

see the full explanation to what this setting does here. 请参阅此处对此设置的完整说明。

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

You might also want to try adding in some logging for your wcf service, see this link 您可能还想尝试为wcf服务添加一些日志记录,请参见此链接

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

It should give you a deeper insight into what is actually going on and whether there are any errors. 它应该使您对实际发生的情况以及是否有任何错误有更深入的了解。 Also sometimes I have seen if the maxconcurrentcalls has been hit it will queue the calls to the service, these are displayed as warnings. 有时我还看到maxconcurrentcalls是否被命中,它将使对服务的调用排队,这些显示为警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM