BottleNeck/delay 调用 WCF 服务时

BottleNeck/delay when Calling WCF service

我使用方法 Do work 创建了一个简单的 WCF 服务,它会休眠 15 秒,然后 return 一个字符串。它是具有多个并发性的单例服务。

客户端(.net Desktop Application)有一个100的for循环来调用这个函数。我想看看我一次可以处理多少个线程并提高性能。

我正在使用 NetTCP 绑定并添加了性能参数

服务器配置

<services>
  <service name="WCFService.WCFService" behaviorConfiguration="mexbahaviour">
    <endpoint address="WCFService" binding="netTcpBinding" contract="WCFService.IWCFService" ></endpoint>
    <endpoint address="WCFService" binding="netNamedPipeBinding" contract="WCFService.IWCFService" ></endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8090/ "/>
        <add baseAddress="net.tcp://localhost:8091/ "/>
        <add baseAddress="net.pipe://localhost/ "/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="mexbahaviour">
      <serviceMetadata httpGetEnabled="true" />
      <serviceThrottling maxConcurrentCalls="300" maxConcurrentSessions="300"
        maxConcurrentInstances="600" />
    </behavior>
  </serviceBehaviors>
</behaviors>

问题是请求到达服务器的速度不够快。初始秒有 4 个请求,但之后每秒有 2 个请求。 The output window on service looks like this.

因此,每当请求命中服务时,都会创建一个新线程并记录接收到它的时间,然后进入休眠状态。

我在客户端添加了连接管理部分

<connectionManagement>
  <add address="*" maxconnection="100"/>
</connectionManagement>

是否是创建线程导致的延迟?或者我遇到的一些服务限制?

请给我一些建议。

我也尝试使用这篇文章来实现,这对我有帮助 Boost WCF Performance

我想,这是基于线程池的一个基本策略。可以修改minThreads如下,

int worker, int io;
ThreadPool.GetMinThreads(out worker, out io); 
ThreadPool.SetMinThreads(worker, 100 - io); // 100 is just sample value.