In-depth analysis of Concurrency and Throttling systems in WCF [7 articles]

Source: Internet
Author: User

The essence of a Service is to provide a certain function that the Service consumer expects. The value of the Service is reflected in two aspects: the quality of the Service itself and the number of consumers on the platform of the boarding Service, concurrency focuses on the second element. To maximize the service utility, you must consider how to use existing resources to achieve the maximum Throughput (Throughput ). Increasing throughput is an important way for a hosted Service Instance to process concurrent access from various clients (Service proxies) at the same time. WCF implements a complete concurrency control system, providing you with different concurrency modes.

I often say that software architecture is an art of trade-offs. We need to consider various conflicting factors and find an optimal combination. Increasing the concurrent access volume allowed by a single service instance can increase the overall throughput. This theory relies on the assumption that the resources available to the server are unlimited. We know that this assumption will not be true under any circumstances. If the concurrency exceeds the critical point that the server can afford, the entire server will crash. Therefore, on the one hand, WCF must allow a single service instance to concurrently process multiple received requests, and also set a gate to control the number of concurrent requests. The Throttling System of WCF creates this gate for you.

[Article 1st]The essence of Concurrency: The same InstanceContext processes multiple service call requests at the same time.

Concurrency means that multiple parallel operations act on the same resource or object at the same time, or the same resource or object simultaneously handles multiple parallel requests. For the concurrency of WCF, the "resource or object" here refers to the Service Instance that carries the final execution of the Service operation ). However, WCF encapsulates a service instance in an instance context object. Therefore, concurrency in WCF means that the same service instance context processes multiple service call requests simultaneously.

A major task of the WCF Server framework is to distribute received service call requests to activated service instances, call corresponding service operations, and return execution results. That is to say, the execution of service operations will eventually be implemented on a specific service instance. Chapter 1 of WCF Technology Analysis (Volume 1) deeply analyzes the instantiation mechanism of WCF, from which we know that in the WCF Server framework system, the activated service instance does not exist independently, but is encapsulated in an instance context object. WCF provides three different instance upper and lower modes (Per-Call, Per-Session, and Single) to implement different context provision mechanisms for service instances. Therefore, the WCF concurrency framework solves the problem of how to effectively process multiple service call requests distributed to the context of the same service instance, these parallel call requests may come from different clients (Service proxies) or the same clients.

[Article 2nd]Synchronization in concurrency -- Implementation of synchronization mechanism in the WCF concurrency System

In the nature of WCF concurrency, we talked about three different concurrency modes provided by WCF, so that developers can choose different concurrent processing policies based on specific situations. For these three concurrency modes, Multiple adopts parallel execution mode, while Single and Reentrant adopt serial execution mode. Serial execution is synchronous execution. In the WCF concurrency framework system, how is this synchronization mechanism implemented?

[Article 3rd]Practice over theory -- create a monitoring program to detect the concurrent processing mechanism of WCF

The concurrency of WCF is for an InstanceContext that encapsulates a service instance (refer to "Essence of concurrency" "synchronization in concurrency"). Therefore, in different instance context modes, it will show different concurrent behaviors. Next, we will analyze the concurrency Processing Mechanism of WCF from the perspective of the specific instance context mode, see Chapter 9th of WCF Technology Analysis (Volume 1.

To give readers a deep understanding of the impact of different instance contexts on concurrency, a simple WCF application is created and the monitoring function is added on this basis, it mainly monitors the execution time of various events, such as the start and end times of client service calls, And the start and end times of service operations. Based on the monitoring information output in real time, readers can have a very intuitive understanding of the concurrent processing of WCF. [Download the source code from here]

[Article 4th]Concurrency and instance context mode: The concurrency performance of the WCF Service in different instance context Modes

Since the concurrency of WCF is for an InstanceContext that encapsulates a service instance, different concurrency behaviors are displayed in different instance context modes. Next, we will analyze the concurrency of WCF from the perspective of the specific instance context mode. If you do not understand the context mode and the mechanism of the Instance context, see Chapter 9th of WCF Technology Analysis (Volume 1.

In the article "practice over theory", I wrote a simple WCF application. Through this application, we can clearly understand the implementation of monitoring client and service operations. In this way, we can intuitively see whether the server uses parallel or serial execution methods for concurrent service call requests. Next, we will make full use of this monitoring program to deeply analyze the concurrency implementation mechanism in different instance context modes by combining instance demonstration and principle analysis.

[Chapter 2]Callback and concurrency: analyze the concurrency control mechanism of WCF in ConcurrencyMode. Reentrant mode through instances

For normal service calls, the request message sent from the client to the server is finally sent to the InstanceContext encapsulated in the service instance when the WCF service is running. In the callback scenario, we also encapsulate the callback object into the InstanceContext object and mail it to the client. When a callback is executed during a service operation, the callback message is finally distributed to the InstanceContext in which the callback object is encapsulated on the client. From the mechanism of message distribution and concurrent processing, there is no essential difference between the two requests. Next, we will analyze the processing mechanism of WCF for concurrent service calls and concurrent callback through examples in practice over theory.

[Article 6th] is the WCF Service in ConcurrencyMode. Multiple mode always executed concurrently? discuss the impact of synchronization context on concurrency [Part 1] [Next]

The previous article demonstrates the impact of synchronization context on concurrency of the WCF Service host through a specific instance, briefly introduces what the synchronization context is, and the application of synchronization context in multithreading. How does the synchronization context affect the execution of service operations in the WCF concurrency system? This actually involves a topic of WCF, namely Thread Affinity. The next article will describe the essence of the WCF Thread Affinity mechanism.

[Article 7th] three barriers to controlling concurrent access: Exploring the Throttling System of WCF [Part 1] [Next]

WCF is a multi-threaded framework for message listening, receiving, and processing. It can handle service call requests from the same or different clients at the same time, and provides a sound synchronization mechanism to ensure status consistency. On the one hand, we expect the WCF server to be able to process as many concurrent requests as possible, but the limitation of resources determines the maximum concurrency. If WCF does not control the number of concurrent requests that enter the message processing system, it tries to process all the concurrent requests that arrive. Once the threshold value is exceeded, the entire server will crash due to resource depletion.

Therefore, we need to set a channel barrier between the message receiving system of WCF and the message processing system to control the requests flowing into the message processing system to an optimal range, to effectively use existing resources, so as to ensure service availability and improve the overall throughput. Throttling allows you to configure these thresholds dynamically based on the existing software and hardware environment.

Author: Artech
Source: http://artech.cnblogs.com
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide a clear link to the original article on the article page. Otherwise, you will be held legally liable.

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.