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
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
- 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.
No comments:
Post a Comment