简体   繁体   中英

How does WCF handle instancing and concurrency?

I try to understand how WCF handles instancing, concurrency and threading.

For example, if I configure the instance context mode to PerCall and concurrency mode to singe, every request creates a new instance of the WCF service. What does that mean related to the threads, which a created server side?

I guess that instancing and concurrency is not strong related to threading. Is it right that, to the given example, every request is queued by the "main" I/O ThreadPool to be executed by the worker thread? Or is every request creating a new instance and thread that executes this request?

if I configure the instance context mode to PerCall and concurrency mode to singe, every request creates a new instance of the WCF service. What does that mean related to the threads, which a created server side?

If you use Per-Call instancing then the service instances are all single threaded, as each incoming request is serviced by a new instance of the service. So specifying concurrency is not relevant in this scenario.

I guess that instancing and concurrency is not strong related to threading

I'm not sure how you arrive at this conclusion.


Addressing comments below this post:

In a Per-Call mode, for each call we create an instance of the service. If we are in a single thread mode, there is one thread handling these instances so we serve requests in a sequential way

These two statements are contradictory. If we create a new instance per request, then the service does not handle multiple requests sequentially. It will create a new instance per request.

(In PerCall mode) if the concurrency mode is multiple, there are many threads executing the instances methods so we serve request in parallel way

This is not correct. Multiple requests will each be handled by their own service instance.

Handling a call in a service instance takes one thread. The call handling code may well be multi-threaded but this is internal to the service and WCF concurrency mode does not affect the execution of call handling code.

Other calls to the service will result in new instances of the service being created. So while you certainly can set concurrency mode to multiple, you will never get more than one thread handling requests to a service instance.

Therefore setting concurrency mode to multiple in per call instancing does not make any practical difference to the behavior of the service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM