Home > WCF > WCF # 14 – WCF Service Behaviour Introduction (Concurrency and Instancing)[Part I]

WCF # 14 – WCF Service Behaviour Introduction (Concurrency and Instancing)[Part I]

 

In the last post of WCF Behaviors we saw WCF Behaviors , their types and how they are important in communication with the other systems in the environment.

In this article , we will see the first type of the WCF Behavior called Service behaviors.

Service behaviors  run at the service level and have access to all of the endpoints. They control items such as instancing and transactions. Service behaviors are also available for authorization and auditing.

** Service Behavior includes two parts  Concurrency and Instancing

Concurrency is a measure of how many tasks can be performed simultaneously
and is measured in tasks (requests, jobs, transactions, and the like).                                       

Execution time is a measure of how long it takes a task to complete and is
measured in time (milliseconds, seconds, and so on).

Throughput is the measure of how many tasks are completed within a fixed time and is
reported as tasks/time (requests/second, transactions/minute, and so on).
Throughput is a function of concurrency and execution time.

There are two ways to increase throughput:  Either decrease execution time or increase concurrency.

Decreasing the execution time for an individual task can be accomplished by either changing the task’s internal algorithm or by adding additional hardware resources, so there’s not much WCF can do about this.

Concurrency can be increased by executing tasks in parallel.

** WCF has two behaviors available for controlling concurrency: 

     a) InstanceContextMode and b) ConcurrencyMode

a) The InstanceContextMode service behavior is used to control instancing and can be set to one of three values:

Single -  One instance of the service class handles all incoming requests. This is called as singleton

PerCall – One instance of the service class is created per incoming request.

PerSession – One instance of the service class is created per client session. When using sessionless channels, all service calls behave as  PerCall even if the InstanceContextMode is set to PerSession.

Note – The default setting, InstanceContextMode.PerSession ,instructs WCF to create a new instance of the service class for each user (proxy, actually) while degrading to PerCall if a sessionless binding is used.

b)  TheConcurrencyMode service behavior is used to control thread concurrency
within a service instance. This behavior can be set to one of three values :

Single – Only one thread at a time can access the service class. This is
the safest setting because service operations do not need to worry
about thread safety.

Reentrant – Only one thread at a time can access the service class, but
the thread can leave the class and come back later to continue.                                                  
Multiple – Multiple threads may access the service class simultaneously.
This setting requires the class to be built in a thread-safe
manner.

Note – The default setting, ConcurrencyMode.Single , instructs WCF to execute only one thread at a time per instance of the service class.

Using these two settings, InstanceContextMode and ConcurrencyMode ,
together enables you to tailor the instancing and concurrency of a service to
address specific performance needs.

you can use following chart to find the right instancing and concurrency of a service.

image

Thank You.

For more Interesting links visit our link resource website http://www.linkmentalist.com/

Advertisements
Categories: WCF
  1. May 8, 2013 at 6:02 am

    An impressive share, I simply given this onto a colleague who
    was doing just a little evaluation on this. And he in truth purchased me breakfast as a result of I discovered it for him.
    . smile. So let me reword that: Thnx for the treat! However yeah Thnkx
    for spending the time to debate this, I really feel strongly about it and love reading more on this
    topic. If potential, as you turn into expertise,
    would you mind updating your weblog with extra details?
    It is extremely useful for me. Huge thumb up for this weblog submit!

  2. May 10, 2013 at 4:15 am

    hey there and thank you for your information – I
    have definitely picked up anything new from right here.
    I did however expertise several technical issues using this web site, since I experienced to reload the site many times previous to I could get it to load correctly.
    I had been wondering if your web hosting is OK?
    Not that I am complaining, but slow loading instances times will very frequently affect your
    placement in google and could damage your high-quality score if ads and marketing with Adwords.
    Anyway I’m adding this RSS to my e-mail and could look out for a lot more of your respective intriguing content. Make sure you update this again soon.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: