同时使用招为何HttpWebRequest对象的性能提升?对象、性能、HttpWebRequest

2023-09-03 16:00:09 作者:我爱的人他已飞走了

我收到了一些非常奇怪的行为,与HttpWebRequest的我希望有人能帮助我。我有一个控制台应用程序,做一些聚集的工作由通过使用HttpWebRequest对象来检索目标网站的内容。由于要求的性质的应用程序是多线程的,并试图使10和30个并发连接(我一直在尝试用一个范围值)之间的任何地方。实际的Web请求的结构如下:

I'm getting some very strange behaviour with HttpWebRequest I hope someone can help me with. I have a console app which does some aggregation work by by using the HttpWebRequest object to retrieve the contents of a target website. Due to the nature of the requirement the app is multithreaded and attempts to make anywhere between 10 and 30 simultaneous connections (I've been experimenting with a range of values). The actual web request is structured as follows:

var req = (HttpWebRequest)WebRequest.Create(url);
WebResponse resp = req.GetResponse();
Stream s = resp.GetResponseStream();
var sr = new StreamReader(s, Encoding.ASCII);
string doc = sr.ReadToEnd();
sr.Close();
resp.Close();
return doc;

反正奇怪的现象是,在正常情况下的应用程序是实现每分钟大约120请求,但如果我打开提琴手它跳到约600。使用Windows 7资源监视器,我可以看到相应的网络活动增加。在控制台进程的TCP连接现在列出远程地址为IPv4的环回,而不是目标服务器的IP地址(预期)。我也想知道由机器允许的,但同时HTTP请求的最大数量在注册表中更改此似乎并没有有所作为。

Anyway, the strange behaviour is that under normal circumstances the app is achieving around 120 requests per minute but if I open up Fiddler it jumps to about 600. Using Windows 7 Resource Monitor I can see the network activity increase accordingly. The TCP connections for the console process now list the remote address as "IPv4 loopback" rather than the target server IP address (expected). I did wonder about the max number of simultaneous HTTP requests allowed by the machine but changing this in the registry does not seem to make a difference.

所以,问题是;它是什么有关运行提琴手这突然增加吞吐量五倍,我怎么能做到这一点的本地机器上,而无需启动另一个工具吗?

So the question is; what is it about running Fiddler which suddenly increases the throughput five-fold and how can I achieve this natively on the machine without needing to launch another tool?

谢谢!

推荐答案

看起来像我现在已经能够得到吞吐量直到通过设置最大连接数(增加一倍,我是越来越有小提琴手开放实际上) App.config中:

Looks like I've now been able to get the throughput right up (to double that I was getting with Fiddler open actually) by setting the max connections in the App.config:

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

非常满意的结果,但我还是有点困惑,为什么有提琴手开放改变了结果,因此大幅提升。

Very happy with the result but am still a little mystified as to why having Fiddler open changed the results so dramatically.