1 minute read

Note: This post refers to .NET Framework for Windows only, and not for the cross-platform .NET Core or simply .NET as it is re-branded in 2020. This means this post is outdated for newer version of .NET

The default throttling settings in WCF has always been very conservative. There where configured conservatively to diminish the risk of request flooding. Without throttling settings a large number of requests will make the service unresponsive by consuming all resources trying to respond to all requests simultaneously.

Because of the very conservative settings many developers have run into what seems like WCF performance problems, but was actually incorrectly configured throttling settings.

WCF throttling is a service behavior configuration and each setting has effect dependent on the InstanceContextMode and ConcurrencyMode settings.

  • maxConcurrentCalls (int) the maximum number of concurrent messages processing
  • maxConcurrentInstances (int) the maximum number of concurrent InstanceContext (service type instances) objects processing
  • maxConcurrentSessions (int) the maximum number of concurrent sessions processing

These throttling settings can be configured in code via the ServiceThrottlingBehavior in the System.ServiceModel.Description namespace or though configuration like below:

<system.serviceModel>
    <serviceBehaviors>
      <behavior name="throttlingServiceBehavior">
        <serviceThrottling maxConcurrentCalls="16"
                           maxConcurrentInstances="160"
                           maxConcurrentSessions="10"/>
      </behavior>
    </serviceBehaviors>
</system.serviceModel>

The default values in .Net 3.0/3.5 are:

  • maxConcurrentCalls = 16
  • maxConcurrentSessions = 10
  • maxConcurrentInstances = maxConcurrentCalls + maxConcurrentSessions

The default has changed in .Net 4.0 as the .Net 3.0/3.5 default values were too conservative and the increase in server resources – especially the number of cores available. The default values for .Net 4.0 are:

  • maxConcurrentCalls = 16 * Environment.ProcessorCount
  • maxConcurrentSessions = 100 * Environment.ProcessorCount
  • maxConcurrentInstances = maxConcurrentCalls + maxConcurrentSessions

The Environment.ProcessorCount property is misleading as the value is the number of cores (Hyper-Threading counts double). In my development laptop with four Hyper-Threading cores looks like this:

WCF Throttling DotNet 4.0 default settings

Comments