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

编程入门 行业动态 更新时间:2024-10-21 20:43:26
本文介绍了同时使用招为何HttpWebRequest对象的性能提升?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我收到了一些非常奇怪的行为,与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> <connectionManagement> <add address="*" maxconnection="30" /> </connectionManagement> </system>

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

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

更多推荐

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

本文发布于:2023-10-29 03:51:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538640.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   性能   HttpWebRequest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!