Multithreading WCF并发

Multithreading WCF并发,multithreading,wcf,configuration,concurrency,Multithreading,Wcf,Configuration,Concurrency,早上好 我有并发问题。我已经创建了一个WCF服务,并对其进行了测试,以确保单个呼叫工作正常。现在我正在执行一些负载测试,我看到超高的CPU利用率和长时间等待请求完成。我的负载测试工具只是一个控制台应用程序,配置为在多个线程上运行ms测试用例以模拟多个客户端。我想知道是否有人能告诉我服务配置的一部分,客户端代理自动生成的配置,或者在服务的代码中,我应该更改以配置它以允许高度并发: 这是我的服务配置文件 <?xml version="1.0" encoding="

早上好

我有并发问题。我已经创建了一个WCF服务,并对其进行了测试,以确保单个呼叫工作正常。现在我正在执行一些负载测试,我看到超高的CPU利用率和长时间等待请求完成。我的负载测试工具只是一个控制台应用程序,配置为在多个线程上运行ms测试用例以模拟多个客户端。我想知道是否有人能告诉我服务配置的一部分,客户端代理自动生成的配置,或者在服务的代码中,我应该更改以配置它以允许高度并发:

这是我的服务配置文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <services>
            <service behaviorConfiguration="Behavior" name="Service.MyService">
                <endpoint address=""
                  binding="netTcpBinding"
                  bindingConfiguration="Security"
                  contract="Service.IMyService">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex"
                  binding="mexTcpBinding"
                  bindingConfiguration=""
                  contract="IMetadataExchange" />        
                <host>
                    <baseAddresses>
                        <add baseAddress="net.tcp://localhost:808/Service" />
                    </baseAddresses>
                    <timeouts closeTimeout="00:01:00" openTimeout="00:05:00" />
                </host>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="Behavior">
                    <serviceMetadata httpGetEnabled="false" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                    <serviceThrottling maxConcurrentCalls="300" maxConcurrentSessions="5000"  maxConcurrentInstances="300" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <bindings>
            <netTcpBinding>
                <binding name="Security" openTimeout="00:05:00" maxConnections="10">
                    <reliableSession inactivityTimeout="00:30:00" enabled="true" />
                    <security mode="None">
                        <transport clientCredentialType="None" protectionLevel="None" />
                    </security>
                </binding>
            </netTcpBinding>
        </bindings>
    </system.serviceModel>
</configuration>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_IMyService" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
            hostNameComparisonMode="StrongWildcard" listenBacklog="10"
            maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
            maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:30:00"
              enabled="true" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign">

            </transport>
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost:808/Service" binding="netTcpBinding"
          bindingConfiguration="NetTcpBinding_IMyService" contract="ServiceReference.IMyService"
          name="NetTcpBinding_IMyService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>
我通读了不止几篇关于MSDN的文章,试图理解在这种情况下我应该怎么做,我似乎已经排除了硬件是这个问题的原因


此外,我已将上述配置中的任何对象名称替换为通用名称,例如MyService和IMyService,它们并不是我真正所说的名称。

如果设置InstanceContextMode=PerCall,则意味着每次调用时都会重新创建服务。检查创建服务的新实例需要多少成本


您可以尝试将其设置为PerSession或Single

走过了我假设的那条路?服务器或客户机上的高Cpu使用率在哪里?或者它们运行在同一个机器上?高CPU使用率在服务器端。它们在不同的盒子上运行。这很难,但是你可以试着分析你的代码。

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]