0

I have a standard Web Service that processes JSON requests via an webHttpBinding. I am trying to find out whether there is a limit on how many concurrent connections it can handle and how to control it. Can't find anything. I am missing something simple or some setting?

Here is a skeleton of my service:

[ServiceContract]
public interface IMyService {...}

[ServiceErrorBehavior(typeof(ErrorHandler))]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService : IMyService {...}
Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48
AngryHacker
  • 59,598
  • 102
  • 325
  • 594

3 Answers3

1

I have some suggestion for this, but this will not be direct config related change. Hold on and read this.

In WCF, there is InstanceContextMode and ConcurrencyMode properties defined for ServiceBehavior. These parameters are configurable only within the service code, and not in XML configuration, because they relate to the runtime behavior of the service and the service developer should be aware of their values. The InstanceContextMode parameter determines how many instances of the service have to be created by the WCF runtime. The possible values are:

  • PerCall: a new InstanceContext object is created for each call.
  • PerSession: a new InstanceContext object is created for each session. If the channel does not create a session this value behaves as if it were PerCall.This is the default value.
  • Single: only one InstanceContext object is used for all incoming calls and is not recycled subsequent to the calls. If a service object does not exist, one is created.

More helpful Blog

Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48
1

Use WCF Service Throttling to control the service.

<behaviors>
  <serviceBehaviors>
    <behavior  name="Throttled">
      <serviceThrottling 
        maxConcurrentCalls="1" 
        maxConcurrentSessions="1" 
        maxConcurrentInstances="1"
      />
    </behavior>
  </serviceBehaviors>
</behaviors>

Always remember that service behaviors do not override limits defined in the host (or binding). For example when using webHttpBinding the default IIS Maximum Concurrent Connections would likely need to be changed for large concurrency values.

Community
  • 1
  • 1
ErnieL
  • 5,773
  • 1
  • 23
  • 27
0

Turns out it has more to do with threading than anything else. The default ASP.NET settings are pretty conservative, so you have to hike them up. Once I did that, the concurrent connections bottleneck completely disappeared.

Make sure you have the following in the appropriate machine.config (not web.config):

<configuration>
  <system.net>
    <connectionManagement>
      <add address="*" maxconnection="100" />
    </connectionManagement>
  </system.net>
  <system.web>
    <processModel 
        autoConfig="true"
        maxWorkerThreads = "100"
        maxIoThreads = "100"
        minWorkerThreads = "50"
        minIoThreads = "50"
         />
    <httpRuntime 
        minFreeThreads="176" 
        minLocalRequestFreeThreads="152" 
    />
  </system.web>
</configuration>

I took all this info from Tuning IIS article by Stuart Brierley. The only thing I changed significantly from his recommendations is maxConnection value.

AngryHacker
  • 59,598
  • 102
  • 325
  • 594