Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 负载测试期间的通信异常_C#_.net_Wcf_Exception Handling_High Load - Fatal编程技术网

C# 负载测试期间的通信异常

C# 负载测试期间的通信异常,c#,.net,wcf,exception-handling,high-load,C#,.net,Wcf,Exception Handling,High Load,我正在开发一个wcf应用程序,我开始看到它有一个奇怪的超时行为。 为了确定问题是否与wcf相关,我创建了一个与实际配置相同的foo应用程序 客户端应用程序代码如下所示: public class Clients { public static void Main(string[] args) { var random = new Random(); var run = true; var threads = 100;

我正在开发一个wcf应用程序,我开始看到它有一个奇怪的超时行为。 为了确定问题是否与wcf相关,我创建了一个与实际配置相同的foo应用程序

客户端应用程序代码如下所示:

public class Clients
{
    public static void Main(string[] args)
    {
        var random = new Random();
        var run = true;
        var threads = 100;

        for (int i = 0; i < threads; i++)
        {
            int delay = random.Next(1000, 1500);

            var t = new Thread(() => {
                var id = Guid.NewGuid().ToString("N").Substring(0, 10);
                var client = new Client(@"client");

                while (run)
                {
                    Console.WriteLine(@"Sending thread id " + id);
                    client.Operation(@"Thread " + id);
                    Thread.Sleep(delay);
                }
            });
            t.Start();
        }
    }
}
这是app.config文件:

<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
  <service name="Test.Service" behaviorConfiguration="throttle">
    <endpoint name="service" 
              address="net.tcp://localhost/service" 
              binding="netTcpBinding" 
              bindingConfiguration="NetTcpBinding" 
              contract="Test.IService"/>
  </service>
</services>
<client>
  <endpoint name="client"
        address="net.tcp://localhost/service"
        binding="netTcpBinding" 
        bindingConfiguration="NetTcpBinding" 
        contract="Test.IService"/>
</client>
<bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding"
             portSharingEnabled="true" 
             closeTimeout="00:01:00" 
             openTimeout="00:00:30" 
             receiveTimeout="00:00:10"
             sendTimeout="00:00:10"
             transactionFlow="false" 
             transferMode="Streamed" 
             transactionProtocol="OleTransactions"
             hostNameComparisonMode="StrongWildcard" 
             maxBufferPoolSize="6553600"
             maxBufferSize="6553600"
             maxConnections="500"
             maxReceivedMessageSize="6553600">
      <readerQuotas maxDepth="128" 
                    maxStringContentLength="3276800" 
                    maxArrayLength="6553600" 
                    maxBytesPerRead="1638400"
                    maxNameTableCharCount="6553600"/>
      <security mode="None">
        <transport protectionLevel="None"/>
      </security>
    </binding>
  </netTcpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="throttle">
      <serviceThrottling maxConcurrentCalls="1000" 
                         maxConcurrentInstances="10"
                         maxConcurrentSessions="500"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
我在四核机器上使用端口共享,该服务是自托管的

这与我在实际应用程序中遇到的问题相同,但超时更高(2分钟半)。我不敢相信300是InstanceContextMode.Single可以处理的最大连接数。我读到关于默认ChannelInitializationTimeout值(设置为5)的问题,但我认为这不是问题所在(在另一个测试中,我开始为所有线程创建并打开一个客户端,并等待6秒来启动所有线程,10秒后的结果是相同的异常)。也许我配置的方式不对

如果有人有线索或想法,他们会很有帮助。提前谢谢

更新


我将绑定从netTcp更改为basicHttpBinding,现在一切正常(没有抛出任何通信异常)。此外,我开始比以前更快地在服务中获取消息,有人知道我为什么在basicHttpBinding中获得这种改进吗?

尝试更新DefaultConnectionLimit属性@戴维兹。当服务是自托管时,此属性是否有意义?是的,我相信,尤其是在自托管的情况下。值得一试。谢谢!我会试试看这是否有效:D@DavidZ.NoDefaultConnectionLimit属性很幸运:(我还尝试了使用自定义绑定的ChannelInitializationTimeout,但没有结果。
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
  <service name="Test.Service" behaviorConfiguration="throttle">
    <endpoint name="service" 
              address="net.tcp://localhost/service" 
              binding="netTcpBinding" 
              bindingConfiguration="NetTcpBinding" 
              contract="Test.IService"/>
  </service>
</services>
<client>
  <endpoint name="client"
        address="net.tcp://localhost/service"
        binding="netTcpBinding" 
        bindingConfiguration="NetTcpBinding" 
        contract="Test.IService"/>
</client>
<bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding"
             portSharingEnabled="true" 
             closeTimeout="00:01:00" 
             openTimeout="00:00:30" 
             receiveTimeout="00:00:10"
             sendTimeout="00:00:10"
             transactionFlow="false" 
             transferMode="Streamed" 
             transactionProtocol="OleTransactions"
             hostNameComparisonMode="StrongWildcard" 
             maxBufferPoolSize="6553600"
             maxBufferSize="6553600"
             maxConnections="500"
             maxReceivedMessageSize="6553600">
      <readerQuotas maxDepth="128" 
                    maxStringContentLength="3276800" 
                    maxArrayLength="6553600" 
                    maxBytesPerRead="1638400"
                    maxNameTableCharCount="6553600"/>
      <security mode="None">
        <transport protectionLevel="None"/>
      </security>
    </binding>
  </netTcpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="throttle">
      <serviceThrottling maxConcurrentCalls="1000" 
                         maxConcurrentInstances="10"
                         maxConcurrentSessions="500"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
System.ServiceModel.CommunicationException: The socket connection was aborted. 
This could be caused by an error processing your message or a receive timeout 
being exceeded by the remote host, or an underlying network resource issue. 
Local socket timeout was '00:00:10'.---> System.Net.Sockets.SocketException: 
An existing connection was forcibly closed by the remote host at
System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 
offset, Int32 size, TimeSpan timeout, Boolean closing)