[英]How to force .NET to open many simultaneous http connections
Here is the very simple scenario I would like to show: 这是我想展示的非常简单的场景:
internal class Program
{
private static void Main(string[] args)
{
var uri = new Uri("http://myserver.com");
ServicePointManager.FindServicePoint(uri).ConnectionLimit = 1000;
for (int i = 0; i < 1000; i++)
{
WebRequest.Create(uri).BeginGetResponse(a => { }, null);
}
Console.WriteLine("done");
Console.ReadLine();
}
}
And corresponding App.config: 并对应App.config:
<system.net>
<connectionManagement>
<clear/>
<add address="*" maxconnection="1000" />
</connectionManagement>
<defaultProxy>
<proxy proxyaddress="http://127.0.0.1:8888" />
</defaultProxy>
</system.net>
Let say myserver.com responds 10 seconds (I emulated this in Fiddler via AutoResponder). 假设myserver.com响应10秒(我在Fiddler中通过AutoResponder进行了仿真)。
In the proxy server (Fiddler) I see that only 14 http requests are sent at application start. 在代理服务器(Fiddler)中,我看到在应用程序启动时仅发送了14个http请求。 Then number of active connections is growing but very slow, about +1 request in 1-2 sec. 然后,活动连接的数量正在增加,但非常缓慢,大约1-2秒内需要+1。 So after 1 minute of work the number of active http requests is about 50, but not 1000. 因此,工作1分钟后,活动的HTTP请求数约为50,但不是1000。
Is there any configuration that I can change to force .NET to open if not 1000 real http request but at least 200-300? 如果不是1000个真正的http请求但至少为200-300,是否可以更改任何配置以强制.NET打开?
I think that the best solution is to open each of the connections in new Thread. 我认为最好的解决方案是在新线程中打开每个连接。
The thread limit is 1023 in .NET 4 32-bit systems 32768 in .NET 4 64-bit systems 在.NET 4 32位系统中的线程限制为1023
If it doesn't work at least you will be sure that there is nothing wrong in your code. 如果至少不起作用,您将确保代码中没有错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.