Calling the HttpWebRequest concurrent connection limit in a multithreaded environment

Source: Internet
Author: User

. NET HttpWebRequest or WebClient have concurrent connection restrictions in multi-threaded situations, which is limited to desktop operating systems such as Windows XP, Windows 7 defaults to 2 and defaults to 10 on server operating systems. If you do not modify this concurrent connection limit, the number of HTTP connections that the client can establish at the same time is only 2 or 10. For some applications, such as browsers or web spiders, 2 or 10 concurrent numbers are too few to significantly affect the performance of the application. This concurrent connection limit is due to the fact that the HTTP 1.0 and HTTP 1.1 standards stipulate that the maximum number of concurrent connections is 2. However, the current mainstream browser has not followed this rule, but the. NET Framework still adheres to this rule by default.

Many articles say that accessing HttpWebRequest asynchronously can improve concurrency, but I test that it is not good to have synchronous or asynchronous access without modifying this default number of concurrent connections.

The way to adjust this default concurrency limit is simple

Just set it in the program:

System.Net.ServicePointManager.DefaultConnectionLimit = 512;

This value should not be more than 1024.

We can also set the maximum number of concurrent connections in app. Config in the following ways:

<Configuration><system. NET><connectionmanagement><AddAddress= "http://www.google.com"maxconnection= "+" /><AddAddress= "*"maxconnection= "+" /></connectionmanagement></System.Net></Configuration>

After modifying this setting, the concurrency performance increased significantly, from the original 20 times per second directly up to 1000 times per second.

Calling the HttpWebRequest concurrent connection limit in a multithreaded environment

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.