c # simulated concurrent requests, only two concurrent connections.

HttpWebRequest concurrent requests using analog when found that no matter how increasing the number of thread, no use, counter to see the server 2 are connected, as shown below (with respect to how to open the counter, Baidu)

 

 

Then search, I found the following needs to be configured in the app.config

<system.net>
<connectionManagement>
<add address="*" maxconnection="1000000"/>
</connectionManagement>
</system.net>

Or added System.Net.ServicePointManager.DefaultConnectionLimit = 1000 before the program starts concurrent calls; (this value is the maximum number of concurrent)

After my test, the two things that will make the number of concurrent concurrent schedule, experimental way is to write a console program A. Inside and issued 100 threads, I see the site of IIS connections A, how about without this code is 2 (I suspect console program is recognized as a browser client, and not only 2 of 10 ), add the code, the number of connections is the number of concurrent me.

 

The problem is solved, but I do have a new question, and since this way, does that mean, suppose I have a page in a web A project is being used to access other people httpwebrequest interface, I assume interface address is api.baidu.com, if there are 50 people at the same time I visited pages a, and I do not press the web.config above configuration, is it my a page can only synchronize two individuals request it?

Then I'll go to practice, to build an environment, free to engage in a page A, page A with httpwebrequest go visit my makeshift site B (equivalent to api.baidu.com mentioned above), I found the site a number of connections can go on, while the number of connections has been site B 10.

This represents concurrent requests on a page is limited to 10 A (reportedly windows server system limit is 10, ordinary win7 xp limit is 2. My Site A is based on the windows server2008)

Then, according to the above-mentioned config change or add codes can increase the number of concurrent, so I added to the System.Net.ServicePointManager.DefaultConnectionLimit = 1000 A in the page page_load; revisit time the page A (corresponding to let a be compiled site is loaded IIS), and then began to use the console 100 concurrent requests and found counter site B, has been 10, no change. . . . . So, I do not understand where this problem, then I try to get rid of this Code, adding the above-mentioned configuration node in web.config, then concurrent 100, the counter and Site B Site A counter They have risen to 100. The first synchronous FIG rise, Web.config site A arranged above said codes

 

 

The following is a web.config FIG site A code configured to cancel the above-mentioned counter

 

 

 

 The results are out, I concluded that if I have an analog station a page request other interfaces where the code above must be configured in the web.config I site inside (even in Canada System.Net page_load .ServicePointManager.DefaultConnectionLimit = 1000;) did not use these words, which in the end is why? I have this code inside the console is definitely a test can be used, so there is to know them, please tell me in the comments area, I appreciate it.

 

Guess you like

Origin www.cnblogs.com/Jerseyblog/p/11454490.html