|
Throttle -- is the mechanism by which the flow of a fluid is managed by constriction or obstruction. |
In WCF
WCF throttling provides some properties that you can use to limit how many instances or sessions are created at the application level.
WCF provides three ways by which you can define upper limits:
|
|
|
MaxConcurrentCalls -- |
Limits the total number of calls that can currently be in progress across all service instances. The default is 16. |
|
MaxConcurrentInstances -- |
Limits the number of service instances that execute at one time across a ServiceHost. The default is Int32.MaxValue. |
|
MaxConcurrentSessions -- |
A positive integer that limits the number of sessions a ServiceHost object can accept. The default is 10. |
Ways of Configuring Service Throttling
1. Administrative (configuration file)
Using <serviceThrottling> tag of the Service Behavior.
Sample : you can configure the maxConcurrentCalls, maxConcurrentInstances , maxConcurrentSessions property as shown below.
<system.serviceModel>
<services >
------------------
------------------
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true "/>
<serviceThrottling maxConcurrentCalls="500"
maxConcurrentInstances ="100"
maxConcurrentSessions ="200"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
2. Programming Model
Using ServiceThrottlingBehavior
Sample: you can set the maxConcurrentCalls, maxConcurrentInstances , maxConcurrentSessions property programmatically as shown below.
ServiceHost objservicehost = new ServiceHost(typeof(MyService));
ServiceThrottlingBehavior objservicethrottle
= objservicehost.Description.Behaviors.Find();
if (throttle == null)
{
objservicethrottle = new ServiceThrottlingBehavior();
objservicethrottle.MaxConcurrentCalls = 1000;
objservicethrottle.MaxConcurrentSessions = 400;
objservicethrottle.MaxConcurrentInstances = 200;
objservicehost.Description.Behaviors.Add(objservicethrottle);
}
objservicehost.Open();
Default settings for throttling for different WCF versions
|
MaxConcurrentSessions |
MaxConcurrentSessions |
MaxConcurrentSessions |
|
WCF 3.0 / 3.5 |
6 |
26 |
10 |
|
WCF 4.0 |
16 * processorcount MaxConcurrentCalls |
MaxConcurrentCalls + MaxConcurrentSessions 100 * processorcount |
100 * processorcount |
Hope You are clear with the concepts.
Happy Coding J
Thanks
Baimey