2013-06-20 22 views
1

这里是很简单的场景,我想表明:如何强制.NET来打开多个并发的HTTP连接

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(); 
    } 
} 

和相应的App.config:

<system.net> 
    <connectionManagement> 
    <clear/> 
    <add address="*" maxconnection="1000" /> 
    </connectionManagement> 
    <defaultProxy> 
    <proxy proxyaddress="http://127.0.0.1:8888" /> 
    </defaultProxy> 
</system.net> 

咱们说MYSERVER。 com响应10秒(我通过AutoResponder在Fiddler中模拟了这个)。

在代理服务器(Fiddler)中,我看到只有14个http请求在应用程序启动时发送。然后,活动连接的数量正在增长,但非常缓慢,约1-2秒内发出+1请求。因此,工作1分钟后,活动http请求的数量约为50,但不是1000.

是否有任何配置可以更改为强制.NET打开,如果不是1000真实http请求但至少200-300 ?

+0

您应该通过阅读响应流并正确处理您的IDisposables来完成WebRequests。你还可以确定提琴手没有施加限制吗?这也可能是有趣的:http://stackoverflow.com/a/1361932/14357 – spender

+0

我试图改变System.Net.ServicePointManager.DefaultConnectionLimit。它没有帮助。顺便说一下,它已经是1000.处理WebResponse也没有帮助。 – Pashec

+0

我在Peuczyński。现在你所要求的只是一个线程。 – Paparazzi

回答

1

我认为最好的解决方案是打开新线程中的每个连接。

线程限制是 1023 .NET 4的32位系统 32768 .NET 4的64位系统

如果不至少工作,你一定会认为没有什么错你的代码。

+0

我已经试过了。没有不同 – Pashec

相关问题