Switch: Concurrent connection limit

Source: Internet
Author: User

Address: http://blog.joycode.com/musicland/archive/2005/04/16/48690.aspx

In the past few days, we have tested the performance of Web Service (WSE 2.0) on IIS 6. Some problems have been found and solved in this process.
One of the questions is interesting. My colleagues in the project team and I found that no matter how many concurrent threads we use the simulated client written in C # to connect to the Web service, the number of concurrent connections monitored by the server (Web Service \ current connections in the performance calculator) is always the maximum of 2 connections per client. This makes it impossible to view the real response of the server in a large amount of concurrency.
So why does the server limit the maximum number of concurrent requests per client?
By searching for information, I found the root cause of the problem. Originally, this practical considerations was proposed for persistent connections in HTTP 1.1 SPEC:
Clients that use persistent connections shocould limit the number of simultaneous connections that they maintain to a given server.A single-user client shocould not maintain more than 2 connections with any server or proxy.A proxy shocould use up to 2 * n connections to another server or proxy, where N is the number of simultaneously active users. These guidelines are intended to improve HTTP response times and avoid congestion.
The above content indicates that, in order to improve the HTTP response time and avoid network congestion, the client in the HTTP connection should not establish more than two HTTP connections with the server. If more requests are required, these requests will be pipeline to the two HTTP connections and asynchronously transmitted to the server. For example, there are hundreds of vehicles (requests) that want to drive from Tianjin to Beijing, but only two roads (HTTP connection) can be built between Tianjin and Beijing ), therefore, if these cars want to drive from Tianjin to Beijing, they can only take these two roads.
However, sometimes it is necessary to break through these limits. For example, in the performance test I mentioned at the beginning, I need to use as few client programs as possible to simulate as many user accesses as possible, instead, 1000 machines cannot be used for testing to simulate 500 concurrent requests at the same time. How can we use a test application to generate a specified number of concurrent tasks?
It is not hard to see that in order to increase the concurrency produced by a single test application, two metrics should be added: the number of network clients and the number of HTTP connections of a single client. As far as I know, the following two methods can be used to improve the two indicators respectively.

Method 1: Use appdomain
In. net, an appdomain is considered as a client in a network connection. Therefore, if you want to simulate multiple clients using a test application, you only need to create multiple AppDomains. It should be noted that for each appdomain, the maximum limit of two connections still exists, the difference is that we can use a test application to send more than two concurrent requests (now we don't need to find 1000 testing machines to simulate 500 concurrent requests ). See the following code:

Appdomain = appdomain. createdomain ("");
Appdomain. executeassembly (@ "testclient.exe ");
Appdomain. Unload (appdomain );

Here, I created a new application domain by calling the static method createdomain of appdomain and asked the application domain to execute an application testclient.exe. The application will be responsible for sending requests to the server (up to two connections can be established ). You can use multiple threads to drive the above Code, so that a large number of application domains are created at almost the same time, so that you can simulate a specified number of clients, and generate the expected concurrent access volume.

Method 2: Use the configuration file
In addition to increasing the number of clients, we can also increase the number of HTTP connections that a single client can establish. It is very easy to achieve this goal in. net, just on the client (yes, it is the client !) Add the following lines to the configuration file:

<Add address = "*" maxconnection = "100"/>

The connectionmanagement node specifies the maximum number of connections that can be established between the client and a network host. The default value in the machine. config file is 2. You can change the quota in the application-level configuration file. The address attribute indicates which network address the connection quota is for, and * indicates all network hosts. If you write address = "www.google.com", it indicates that the following maxconnection is only applicable to Google access.
Now you can change the configuration as needed. If you change the value of maxconnection to 1000, the maximum number of connections that can be established between your test application and the server is the number of application domains used for testing * 1000. Test it!

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.