InstanceContext and ConcurrencyMode in WCF, wcfinstancecontext

Source: Internet
Author: User

[Switch] In WCF, InstanceContext, ConcurrencyMode, and wcfinstancecontext

I. Preface

Recently, I am busy with the company's online upgrade project. One person is responsible for the online upgrade of the company's four main products. These four products exist in Revit in the form of plug-ins. Currently, they are implemented based on WCF. When the total number of customers exceeds 50 thousand, the socket is used again.

Due to the concurrent server operations, you should study the InstanceContext and ConCurrencyMode of WCF, find a lot of articles, do not write this concise statement, special forwarding reserved.

 

Ii. original content

Original Author's copyright information ************************************* **************************************** ***********************************

Original works can be reprinted. During reprinting, you must mark the original source, author information, and this statement in hyperlink form. Otherwise, legal liability will be held. Http://arthurshayne.blog.51cto.com/3491820/1241514

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

 

Today I learned the lecture 9th from instructor Xu Changlong <learn WCF from scratch with me> <session, instance and concurrency>, I checked the instance and concurrency online and found a good article to recommend it to everyone.

From this, I will talk about some of my views on the instance and concurrency. The instance and concurrency are not the same thing, but they have an impact on each other. Below I will give some interesting examples to talk about my understanding of the examples and concurrency in WCF.

According to this document, the WCF instance is specified through the InstanceContext attribute. The optional values are Single, PerSession, and PerCall. Concurrency is specified through the ConcurrencyMode attribute. The valid values are Single, Multiple, and Reentrant. There are 3*3 = 9 combinations. The Reentrant concurrency mode is essentially a special case of Single. InstanceContext is used to control the number of service objects. ConcurrencyMode is used to control whether a service object can serve multiple requests at the same time.

Let's start with an example. If our service is for breakfast, InstanceContext decides that we have several masters to do breakfast, concurrencyMode determines that each master can only do the same thing one by one or at the same time. The following sections describe the situations one by one:

1. InstanceContext = Single & ConcurrencyMode = Single

InstanceContext = Single. We will be a master.

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

It is not hard to imagine that if there are more people to buy breakfast, there will be a long queue, and if there is a person in front of five sets of breakfast, then the people behind can only wait for that person to finish their turn. It is good to do one thing at a time if you do not have high requirements on the master's ability.

2. InstanceContext = Single & ConcurrencyMode = Multiple

InstanceContext = Single. We will be a master.

ConcurrencyMode = Master Multiple simultaneously

This is what the boss wants to do early, and the minimum number of people is the most, but the requirements for the master who wants to do early work are very high, and a lot of things should be done at a time. If there are no more people, they will make a mess. They will make less cake of Michael Jacob and more soy milk of Michael Lee.

3. InstanceContext = PerSession & ConcurrencyMode = Single

InstanceContext = PerSession provides each customer with a dedicated master service (when a customer comes here, the customer will be dismissed after leaving)

ConcurrencyMode = Single: only one master works at a time. Each master can only do one thing at a time.

This is not possible in real life, but it is very common in computers. Therefore, my example only describes the key issues. Please do not be too truthful. At this time, the first customer will have a dedicated master to serve, but we only have one kitchen and can only accommodate the next master, while other masters can only wait for the master who serves Michael to serve breakfast. The master can only do one thing at a time. If a customer wants a lot of things, the master will do the same thing. All we can do is to have multiple masters in a single thread. It is good to do one thing at a time if you do not have high requirements on the master's ability.

4. InstanceContext = PerSession & ConcurrencyMode = Multiple

InstanceContext = PerSession provides each customer with a dedicated master service (when a customer comes here, the customer will be dismissed after leaving)

ConcurrencyMode = all masters work at the same time, and each master can do all the work at the same time.

This is also impossible in real life. At this time, each customer will have a dedicated master to serve, and the master can work at the same time, and the master can do all the work at the same time. The master has high requirements, because it only processes all the breakfast records of a customer at the same time.

5. InstanceContext = PerCall & ConcurrencyMode = Single

InstanceContext = PerCall provides a dedicated master service for each customer's needs (the master is dismissed after the customer makes the request)

ConcurrencyMode = Single: only one master works at a certain time, and each master does only one thing.

This is also impossible in real life. There are more masters now. Like case 3, only one master can work at a certain time. The difference is that the master only does one thing. I don't have high requirements on the capabilities of masters. It is good to do one thing well.

6. InstanceContext = PerCall & ConcurrencyMode = Multiple

InstanceContext = PerCall provides a dedicated master service for each customer's needs (the master is dismissed after the customer makes the request)

ConcurrencyMode = all the masters of Multiple work at the same time, and each master only needs to do one thing.

This is also impossible in real life. At this time, the customer's satisfaction is theoretically the highest. Each requirement of the customer is done by the master, and all the masters are doing at the same time. Of course, this is the biggest price for the boss of the store. I don't have high requirements on the capabilities of masters. It is good to do one thing well.

7. InstanceContext = * & ConcurrencyMode = Reentrant

This is a special case. If we don't make breakfast, we will buy it from another store early and then hand it over to the customer. In this case, if the customer says what it will take 5 seconds, we will call the customer to ask for it, and it will take 1 minute for the other store to deliver things, it will take five seconds to deliver the delivered items to the customer. It can be seen that the in-store processing time is 10 s, and a large amount of time is spent on goods delivery (calling other services ). Therefore, it is reasonable to use the time for goods delivery to handle the customer's requirements. In this one minute, we can handle the needs of 20 customers, in addition, 20 goods transfer requests have been sent. After the delivery of the goods to 1st customers, the customer will be transferred back to complete the remaining services, which can save a lot of time for subsequent customers to wait. The value of InstanceContext is similar to that of ConcurrencyMode = Single, but it is optimized for external calls.

The high or high requirements on the master I mentioned above indicate that our program needs to handle thread security to ensure that our program will not encounter errors in the case of multithreading. If the master does not have high requirements, the concurrency does not exist. The above is my personal understanding of InstanceContext and ConcurrencyMode. If you have any questions, please advise.

 

 

Original copyright information ************************************* *************************************

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

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.