WCF Service Throttling Behaviour

WCF provide us a good way of extensibility to customize various WCF capabilities. We can customize Encoding message, Intercepting parameters etc. and extend the behaviour. Throttling behaviour of service plays an important role and can be set behaviour properties according to our business needs. Below are three important properties for optimizing our WCF service behaviour

1. MaxConcurrentCalls

It just specify the maximum number of messages actively processed across all the dispatcher object in a ServiceHost object. Also each channel can have 1 pending message with it that is not counted until WCF begins to process it.

2. MaxInstances

It just specify the maximum number of InstanceContext object in the service. If a message arrives when  InstanceContext objects are at maximum number, then that messages is kept for waiting until an InstanceContext object is closed.

3. MaxConnections

How many maximum number of channels can be accepted by a ServiceHost is defined using this property. This property is mostly used with sessions context. Messages are on channels and these channels are in queue for processing. There can be one pending channel against each listener object. MaxConnections are counted for active channels only and pending channels are not counted in it.

 

Important Relationship between properties :

ServiceBehaviorAttribute.ConcurrencyMode         <====> ConcurrencyMode.Single

ServiceBehaviorAttribute.InstanceContextMode  <====> MaxInstances

 

Question/Answer:

  • If MaxConcurrentCalls property has been set to 10 along with ConcurrencyMode = ConcurrencyMode.Single ,which one will get more weight and consider?

Ans :  MaxConcurrentCalls setting is ignored in this case and ConcurrencyMode is given weight and priority.

  • If we set System.ServiceModel.ServiceBehaviorAttribute.InstanceContextMode = InstanceContextMode.PerSession or ServiceBehaviorAttribute.InstanceContextMode = InstanceContextMode.Shareable , then how many context would be there?

Ans:   It will equal to Total number of sessions. 

  • If ServiceBehaviorAttribute.InstanceContextMode=InstanceContextMode.PerCall , then how many context would be there?

Ans: It will equal to the number of concurrent calls.