title: WCF not handle 1000 call per second
body: <p>I am working on a WCF Service that is hosted in Windows Service, using nettcpbinding.</p>
  
  <p>when i tried to perform load test on the service i built a simple client that call the service about 1000 call in second, the return from the service take about 2 to 8 seconds at first and after leaving the simple client running for about half hour the time to return the result increased, and some client gives some time out exceptions for the send time which was configured to be 2 minutes.</p>
  
  <p>i revised the service throltting configuration and it's like this </p>
  
  <p>these are the steps i tried to perform:</p>
  
  <ol>
  <li><p>revised the service throttling configuration</p>
  
  <p><code>&lt;serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentInstances="2147483647" maxConcurrentSessions="2147483647"/&gt;</code></p></li>
  <li>was working on Windows 7 machine, so i moved to server 2008 but the same result.</li>
  <li><p>update the configuration of tcp binding to be like the following
  NetTcpBinding baseBinding = new NetTcpBinding(SecurityMode.None, true);
              baseBinding.MaxBufferSize = int.MaxValue;</p>
  
  <pre><code>        baseBinding.MaxConnections = int.MaxValue;
          baseBinding.ListenBacklog = int.MaxValue;
          baseBinding.MaxBufferPoolSize = long.MaxValue;
  
          baseBinding.TransferMode = TransferMode.Buffered;
          baseBinding.MaxReceivedMessageSize = int.MaxValue;
          baseBinding.PortSharingEnabled = true;
          baseBinding.ReaderQuotas.MaxDepth = int.MaxValue;
          baseBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
          baseBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
          baseBinding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
          baseBinding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
          baseBinding.ReliableSession.Enabled = true;
          baseBinding.ReliableSession.Ordered = true;
          baseBinding.ReliableSession.InactivityTimeout = new TimeSpan(23, 23, 59, 59);
  
  
          BindingElementCollection elements = baseBinding.CreateBindingElements();
          ReliableSessionBindingElement reliableSessionElement = elements.Find&lt;ReliableSessionBindingElement&gt;(); 
          if (reliableSessionElement != null)
          {
              reliableSessionElement.MaxPendingChannels = 128;
  
  
  
              TcpTransportBindingElement transport = elements.Find&lt;TcpTransportBindingElement&gt;();
  
              transport.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = 1000;
  
              CustomBinding newBinding = new CustomBinding(elements);                    
              newBinding.CloseTimeout = new TimeSpan(0,20,9);
              newBinding.OpenTimeout = new TimeSpan(0,25,0);
              newBinding.ReceiveTimeout = new TimeSpan(23,23,59,59);
              newBinding.SendTimeout = new TimeSpan(0,20,0);
              newBinding.Name = "netTcpServiceBinding";
  
              return newBinding;
          }
          else
          {
              throw new Exception("the base binding does not " +
                  "have ReliableSessionBindingElement");
          }
  </code></pre></li>
  <li><p>changed my services function to use async and await</p>
  
  <pre><code>public async Task&lt;ReturnObj&gt; Connect(ClientInfo clientInfo)
  {
      var task = Task.Factory.StartNew(() =&gt;
      {
          // do the needed work
          // insert into database
          // query some table to return information to client
      });
  
  
      var res = await task;
      return res;
  }
  </code></pre>
  
  <p>and updated the client to use async and await in it's call to the service.</p></li>
  <li>applied the Worker thread solution proposed in this link
  <a href="https://support.microsoft.com/en-us/kb/2538826" rel="nofollow">https://support.microsoft.com/en-us/kb/2538826</a>
  although i am using .net 4.5.1, and set the MinThreads to 1000 worker and 1000 IOCP</li>
  </ol>
  
  <p>after all this the service start to handle more requests but the delay still exist and the simple client take about 4 hours to give time out</p>
  
  <p>the strange thing that i found the service handle about 8 to 16 call within 100 ms, regarding the number of threads currently a live in the service.</p>
  
  <p>i found a lot of articles talk about configuration needed to be placed in machine.config and Aspnet.config, i think this is not related to my case as i am using nettcp on windows service not IIS, but i have implemented these changes and found no change in the results.</p>
  
  <p>could some one point me to what i am missing or i want from the service something it can't support?</p>