Total Pageviews

Tuesday, August 28, 2012

WCF- Instance and Concurrency Management


When we design our enterprise application, we need to provide a great scalability, performance, throughput, transactions, reliability etc. Sincerely there is no one-fit solution to solve all our needs, but WCF can help us solving all those architectural requirements using different techniques. One of those technique is Instance and Concurrency Management, available through WCF service behaviors, discussed in this article.
Behaviors are classes which are used in WCF runtime operations and basically there are three types of behaviors:
  • Service behaviors - control items such as instancing and transactions
  • Endpoint behaviors - used for inspecting incoming or outgoing messages
  • Operation behavior - well suited for manipulating serialization, transaction flow and parameter handling for a service operation
Also, there is something called Callback behavior, similar to service behavior used for controlling endpoints in duplex communication.

Concurrency and Instancing


One of the great thing in WCF is actually the opportunity to increase the throughput of the service by increasing the concurrency meaning executing different tasks in parallel. WCF can control concurrency by the following two behaviors: InstanceContextMode and ConcurrencyMode.
Instance Management is a set of techniques helping us to bind all client requests to service instances governing which instance handles which request. In order to get familiar with all instance management modes we should take a brief overview on all of them. Basically there are three instance modes in WCF:
  • Per-Session instance mode
  • Per-Call instance mode
  • Singleton Instance Mode
On the other side, Concurrency Management is used to control thread concurrency within a service instance:
  • Single - This is the default setting and instruct the runtime to allow access on one thread per instance of the service class. This setting is the safest one 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. 
http://mkdot.net/community/mknetug/b/dejan/archive/2008/04/29/wcf-service-behaviors-instance-and-concurrency-management.aspx

No comments:

Post a Comment