.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Jean Paul
SP
satyapriyanayak
ASPEvil
Ashutosh Jha

Home >> Articles >> WCF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

WCF throttling

Posted By:Baimey Rajesh       Posted Date: December 05, 2012    Points: 25    Category: WCF    URL: http://baimey.wordpress.com  

A mechanism to limit how many instances or sessions are created at the application level.
 

Throttling

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


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend