"Go" InstanceContext and ConcurrencyMode in WCF

Source: Internet
Author: User

First, preface

Recently busy with the company's online upgrade project, a person responsible for the company's four major products online upgrade, these four products are in the form of a plug-in in Revit, is currently based on WCF. And so the total number of customers exceeded 50,000, and then re-use socket implementation.

Because of the server concurrency, so to study the WCF InstanceContext and ConcurrencyMode, find a lot of articles, not this write concise, special forwarding reservations.

Ii. contents of the original text

Original author Copyright Information ******************************************************************************************************** ********

Original works, allow reprint, please be sure to use hyperlinks in the form of the original source of the article, author information and this statement. Otherwise, the legal liability will be investigated. http://arthurshayne.blog.51cto.com/3491820/1241514

*************************************************************************************************************** ************

Today, I learned Xu Changlong teacher's << with me from the beginning of the wcf>> to learn the 9th talk << session, instance and concurrency >>, the instance and concurrency a bit confused so go online check, found a good article recommended to everyone http:// Www.codeproject.com/Articles/89858/WCF-Concurrency-Single-Multiple-and-Reentrant-and#Instance.

This paper discusses some of their own views on instances and concurrency, and the instances and concurrency are not the same thing, but have an impact on each other. Let me give you some interesting examples of my understanding of instances and concurrency in WCF.

First of all, the instance of WCF is specified by the InstanceContext property, and the value can be single, PerSession, Percall. Concurrency is specified by the ConcurrencyMode property, which can be taken as a single, multiple, reentrant. There are 3*3=9 of their combinations. The concurrency pattern of reentrant is essentially a special case of single and is discussed at the end. InstanceContext is used to control the number of service objects, and ConcurrencyMode is used to control whether a service object can serve multiple requests at the same time.

Well, let's start with an example, if our service is to do breakfast, InstanceContext decided that we have a few teachers to do breakfast, and ConcurrencyMode decided that each teacher can only one to do or at the same time to do together. Let's start by explaining each of the following:

1. InstanceContext = single & concurrencymode = Single

InstanceContext = Single We're going to have to shop earlier, a master.

ConcurrencyMode = Single Master can only do one thing at a time

It is not difficult to imagine that if the purchase of more people will be long line, and if there is a person in front of 5 sets of breakfast, then the person behind can only wait for the person to finish their turn. The ability of the teacher is not high, a good thing at once.

2.InstanceContext = single & concurrencymode = multiple

InstanceContext = Single We're going to have to shop earlier, a master.

ConcurrencyMode = Master multiple to do the same thing at the same time.

This is the situation that the boss wants to shop early, hire the least people to do the most things, but to do early teacher requirements very high, one should do a lot of things. Not a lot of people do mess up the Zhang San of the sesame seed less do one, the John Doe of soy milk to do a bowl and so on.

3.InstanceContext = PerSession & concurrencymode = Single

InstanceContext = PerSession provides a dedicated service for each customer (when the customer comes, the customer is dismissed after leaving)

ConcurrencyMode = single At a time only one master works, each teacher can only do one thing at a time.

This cannot exist in real life but is very common in computers, so my example is just a matter of explaining the key, please don't be too serious. At this time the first customer will have a dedicated master to serve, but we only have a kitchen and can only tolerate a master, to the Zhang San service of the master to do breakfast when other teachers can only wait. A teacher can only do one thing at a time, if a customer wants a lot of things, the same as the teacher to do. So it can be single-threaded only a number of teachers. The ability of the teacher is not high, a good thing at once.

4.InstanceContext = PerSession & concurrencymode = multiple

InstanceContext = PerSession provides a dedicated service for each customer (when the customer comes, the customer is dismissed after leaving)

ConcurrencyMode = Multiple All the Masters work at the same time, each teacher can do all the things he wants to do at the same time.

It is impossible to exist in real life. At this time each customer will have a dedicated master to serve, and the master can work at the same moment, and the master can do all the earlier to do all. The demand for the master is higher, because it only deals with all the breakfast of a customer at the same time.

5. InstanceContext = percall & concurrencymode = Single

InstanceContext = Percall provides a professional service for each requirement of each customer (when the customer asks for it, the teacher is dismissed after he has finished)

ConcurrencyMode = Single A teacher works only one time, and each teacher only does a thing.

It is impossible to exist in real life. This teacher more, and situation 3 in a moment can only have a teacher to work, the difference is that the teacher only for one thing. To master the ability to request is not high, can do a good thing.

6. InstanceContext = percall & concurrencymode = multiple

InstanceContext = Percall provides a professional service for each requirement of each customer (when the customer asks for it, the teacher is dismissed after he has finished)

ConcurrencyMode = Multiple All the master works at the same time, each teacher only for one thing.

It is impossible to exist in real life. At this time the customer satisfaction is theoretically the highest, the customer every request has a master to do, and all the master at the same thing. Of course, this is the biggest price the boss will pay for the early shop. To master the ability to request is not high, can do a good thing.

7. InstanceContext = * & concurrencymode = reentrant

This situation is very special, if we do not produce early all from other early shop to buy and then hands down to customers, the legendary riding donkey. At this time, if the customer say what needs to take 5 seconds, we call to other stores to ask for, other stores to send things to take 1 minutes, and then send the goods to the customer's hands need 5s of time. Visible in-store processing time is 10s, a lot of time in the time of the transfer (call other services). So at this point more reasonable treatment is, the use of the time to deal with the customer needs, in this 1 minutes to deal with the needs of 20 customers, and 20 transfer requests have been sent. Wait until the delivery of the 1th customer and then turn back for it to complete the rest of the service, which can save a lot of time behind the customer waiting. InstanceContext regardless of the value of the ConcurrencyMode = single is almost only for the case of external calls are optimized.

As I mentioned above, the requirement for the master is high or higher, it also indicates that our program needs to do some thread-safe processing to ensure that our program will not error in multi-threaded situations. The case that the teacher is not high is that there is no concurrency. The above is my personal understanding of InstanceContext and ConcurrencyMode, if there is something wrong, please advise.

Original copyright Information **************************************************************************

This article is from the "only text cut time" blog, please be sure to keep this source http://arthurshayne.blog.51cto.com/3491820/1241514

"Go" InstanceContext and ConcurrencyMode in WCF

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.