WCF Service Throttling Behavior

No.of Views6878
Bookmarked0 times
Downloads 
Votes0
By  rajendradhanora   On  28 Sep 2010 11:09:19
Tag : WCF , Security
WCF Service Throttling is a way for you to limit (“throttle”) the throughput of your service so that resources (memory, CPU, network, etc.) are kept at healthy levels.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

WCF Service Throttling is a way for you to limit (“throttle”) the throughput of your service so that resources (memory, CPU, network, etc.) are kept at healthy levels.

While it is not a direct instance management technique, throttling enables you to restrain client connections and the load they place on your service. Throttling enables you to avoid maxing out your service and the underlying resources it allocates and uses. When throttling is engaged, if the settings you configure are exceeded, WCF will automatically place the pending callers in a queue and serve them out of the queue in order. If the client's call timeout expires while pending in the queue, the client will get a TimeoutException.

Using the behaviorConfiguration tag, you add to your service a custom behavior that sets throttled values.

<system.serviceModel>
   <services>
      <service name = "MyService" behaviorConfiguration = "ThrottledBehavior">
         ...
      </service>
   </services>
   <behaviors>
      <serviceBehaviors>
         <behavior name = "ThrottledBehavior">
            <serviceThrottling
               maxConcurrentCalls     = "12"
               maxConcurrentSessions  = "34"
               maxConcurrentInstances = "56"
            />
         </behavior>
      </serviceBehaviors>
   </behaviors>
</system.serviceModel>

I have done following test on wcf service for service throttling in different scenarios:

1.  If maxConcurrentCalls =2 then I made 3 calls to service it will execute only two calls at a time remaining call put into the queue execute after first two calls. See following program

<serviceThrottling
               maxConcurrentCalls="2"
               maxConcurrentSessions="34"
               maxConcurrentInstances="56"
            />

Code

static void Main(string[] args)
        {
            System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(test1));
            th.Start();
            System.Threading.Thread th1 = new System.Threading.Thread(new System.Threading.ThreadStart(test2));
            th1.Start();
            System.Threading.Thread th2 = new System.Threading.Thread(new System.Threading.ThreadStart(test3));
            th2.Start();

            Console.ReadLine();
        }static void test1()
        {
            ServiceReference1.Service1Client o = newConsoleApplication1.ServiceReference1.Service1Client();
           Console.WriteLine("Istance1  " + o.GetData(1));
       }static void test2()
        {
            ServiceReference1.Service1Client o = new ConsoleApplication1.ServiceReference1.Service1Client();
            Console.WriteLine("Istance2  " + o.GetData(2));
        }static void test3()
        {
            ServiceReference1.Service1Client o = new ConsoleApplication1.ServiceReference1.Service1Client();
            Console.WriteLine("Istance3  " + o.GetData(3));
        }

Result 

Image Loading

Each call is taking 5 second to complete.In this sample first two calls execute simaultiniiously and remaining one call executes after 5 seconds.

2. Iif maxConcurrentCalls =3 then I made 3 calls to service it will execute simultaneously

<serviceThrottling
               maxConcurrentCalls="3"
               maxConcurrentSessions="34"
               maxConcurrentInstances="56"
            />

Result 

Image Loading

3. If maxConcurrentCalls =3 and maxConcurrentSessions="2" then only two calls will be executed rest one call is discarded and any exception will not be raised

<serviceThrottling
               maxConcurrentCalls="3"
               maxConcurrentSessions="2"
               maxConcurrentInstances="56"
            />

Result 

Image Loading

4. If maxConcurrentInstances="2" then same result found

<serviceThrottling
               maxConcurrentCalls="3"
               maxConcurrentSessions="12"
               maxConcurrentInstances="2"
            />

Result 

Image Loading

Note: Above result is found with default InstanceContextMode and ConcurrencyMode

That is,

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall,ConcurrencyMode=ConcurrencyMode.Single)]

That's all. hope help.thank you for reading.

 
Sign Up to vote for this article
 
About Author
 
rajendradhanora
Occupation-Not Provided
Company-Not Provided
Member Type-Fresh
Location-Not Provided
Joined date-28 Oct 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top