HttpWebRequest 高效并发问题

默认请求连接数 是2,在服务器操作系统上默认为10. 如果不修改这个并发连接限制,那么客户端同时可以建立的 http 连接数就只有2个或10个。

System.Net.ServicePointManager.DefaultConnectionLimit 这个可以获取到当前默认设置的 最大连接数。

调整一下System.Net.ServicePointManager.DefaultConnectionLimit的值到500,速度一下提高好几倍。其他有很多的博主也遇到过类似的问题,借鉴他们的处理方式。

1.代码配置

   System.Net.ServicePointManager.DefaultConnectionLimit = 512; // 这个值最好不要超过1024。

2.app.config   

<configuration>
<system.net> <connectionManagement>
<!--指定地址--> <add address = "http://www.baidu.com" maxconnection = "512" />

<!--任意地址-->
<add address = "*" maxconnection = "512" /> </connectionManagement> </system.net> </configuration>

猜你喜欢

转载自www.cnblogs.com/itclw/p/9007121.html