This document discusses WCF concurrency modes and throttling. It explains that in single mode, only one thread can use instances of the WCF service class at a time. In multiple mode, each thread has its own instance and can execute concurrently. Reentrant mode is similar to single mode in that only one thread can access an instance at a time, but other threads can execute if the first thread calls another service or processes a callback. The concurrency mode may not have much impact when using per-call instance context mode or for stateless services.
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Wcf concurency
1. Understanding WCF Concurrency Modes and Throttling
1. Single:
Trong Single mode, sẽ có chỉ có một thread có thể sử dụng các ví dụ của WCF lớp dịch vụ.
Nếu bất kỳ chủ đề đã tạo một thể hiện của lớp sau đó tiếp tục yêu cầu đề có thể tạo ra các ví dụ
nhưng họ sẽ phải đợi cho chủ đề đầu tiên để kết thúc sử dụng cá thể của nó và sau đó nó sẽ có
được một sự thay đổi để thực hiện các hoạt động trên cá thể của nó.
Không quan tâm tới thằng InstanceContextMode (per call, per seasion, single).
2. Multiple
In Multiple mode, each thread will have its own instance of the WCF service object and they all
will be executing at the same time. Now this is the most complicated mode because all the
concurrency issues must be handled by the service.
Now let us see what is the behavior with various InstanceContext Modes:
- InstanceContextMode.Single: In this mode, only one instance will serve all the client requests and
since the ConcurrencyMode is also set to Multiple, multiple threads will be created for all the
clients.
- InstanceContextMode.PerSession:Now in this mode, single instance of the service will be
created for each client and since the ConcurrencyMode is set to Multiple, mulitple threads can be
created for each client request.
- InstanceContextMode.PerCall: Now in this mode a new instance is created for every call so
ConcurrencyMode set as Multiple will not have much impact on behavior and every call will be
processed in a single thread.
3. Reentrant
- The Reentrant mode is similar to the Single mode in a way that each thread can create its own
instance but to execute the instance, they will have to wait for any other thread to finish using the
instance. The main difference in this mode is that if the first thread's instance either calls some
other service or process the client callback, the second thread's instance will be given a chance to
execute.
2. - Now since this is similar to Single mode and allows only one thread to process the instance at a
time, this behavior will be same irrespective of the instance mode. i.e. in
InstanceContextMode.Single, InstanceContextMode.PerSession and
InstanceContextMode.PerCallonly a single thread will be allowed to access the instance of the
WCF service class but as soon as the instance calls any other service or go for processing client
callbacks, the other thread will get a chance to execute its own instance of WCF service class.
- Note: We have only talked about the ConcurrencyModes from a theoretical perspective. In most
cases the ConcurrencyMode.Single is used. Also, it in a stateless scenario, where the default
instance mode is PerCall, making a change in the ConsurrencyMode will not have any
effect/impact and thus there will rarely be a case when we would want to change the default
behavior of the concurrency mode (and even if we change it, it will be futile).