title: Performance issue with WCF service (hosted in IIS) being hit with 20 concurrent requests
body: <p><strong>The problem:</strong>
  I have a WCF service that I'm trying to performance test with <a href="http://jmeter.apache.org/" rel="nofollow noreferrer">JMeter</a> and I've noticed that the service response times increase significantly when more concurrent requests are sent.    The first concurrent request returns in the expected amount of time, but each subsequent request takes an increasing amount of time - so that the last request can take double the time of the first.</p>
  
  <p>Here is a screenshot of a run in JMeter:
  <img src="https://i.stack.imgur.com/fbW6x.png" alt="Performance Test Results"></p>
  
  <p><strong>The Code:</strong>
  I have stripped back the WCF service to bare minimum, so all the service method just contains a Thread.Sleep() to simulate a slightly longer running process.</p>
  
  <pre><code>[ServiceContract]
  public interface IAvailabilityService
  {
    [OperationContract]
    Thing GetSomething(Request request)
  }    
  
  [ServiceBehavior(
    InstanceContextMode = InstanceContextMode.PerCall, 
    AddressFilterMode = AddressFilterMode.Any)]
  public class AvailabilityService : IAvailabilityService
  {
    public Thing GetSomething(Request request)
    {
      Thread.Sleep(20000);
      return new Thing();
    }
  }
  </code></pre>
  
  <p>The service is configured as follows:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service name="MyService.AvailabilityService"
                 behaviorConfiguration="DefaultServiceBehavior"&gt;
          &lt;endpoint address="" 
                    binding="basicHttpBinding"
                    bindingConfiguration="bindingConfig"
                    contract="MyService.IAvailabilityService" /&gt;
        &lt;/service&gt;      
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="DefaultServiceBehavior"&gt;      
            &lt;serviceMetadata httpGetEnabled="true"/&gt;      
            &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="bindingConfig"&gt;
            &lt;security mode="None"&gt;
              &lt;transport clientCredentialType="None" /&gt;
              &lt;message establishSecurityContext="false" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I have also tried configuring the service to run as other standard HTTP bindings.  Also I have tried upping the service throttling levels on the binding configuration (though I'm sure that for 20 requests the defaults should be fine).</p>
  
  <p><strong>Service Set-up:</strong>
  The service is running in IIS 6.1 on Windows Server 2008 R2 in .NET 3.5.
  Though we have also seen the same behaviour on IIS 7.</p>
  
  <p><strong>Service Trace:</strong>
  I have turned on tracing and this has revealed that the service always takes around 20 seconds to process each response, but the recieve bytes on connection has a staggered start time which reflects the differences in time reported by JMeter.  </p>
  
  <p>Does this suggest a lag in service activation by IIS?  It can't be a concurrency issue in WCF as you would expect the last thread to be 20x the execution of the first.</p>
  
  <p>Thanks in advance</p>
  
  <p>Iain</p>
  
  <p><strong>UPDATE</strong>
  I've managed to get to a consistent response by increasing the number of worker processes in IIS to match the number of concurrent requests that I want the service to handle (20) - making  the site a <a href="http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/659f2e2c-a58b-4770-833b-df96cabe569e.mspx?mfr=true" rel="nofollow noreferrer">Web Garden</a>.  Though it surprises me that you need to do this in order to get a consistent level of performance from WCF.  </p>
  
  <p>I'll leave the question open a couple more days in case anyone has any better ideas.</p>