. 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