HttpWebRequest和I / O完成端口 [英] HttpWebRequest and I/O completion ports

查看:156
本文介绍了HttpWebRequest和I / O完成端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,需要一个类型的消息去触及数据库和其它类型的消息去和打一些外部XML API的应用程序。

i'm working on an application that requires for one type of message to go hit a database, and the other type of message to go and hit some external xml api.

我要处理大量...的巨大挑战之一是获得HttpWebRequest类表现良好。我最初开始时只有使用标准的同步方法和threadpooling整个事情。这是不好的。

i have to process A LOT... one of the big challenges is to get HttpWebRequest class performing well. i initially started with just using the standard synchronous methods and threadpooling the whole thing. this was not good.

打完有点读我看到reccomended办法做到这一点是使用的开始/结束的方法来工作委托给IO完成端口,从而释放线程池,并产生更好的性能。这似乎不是如此......表现略好,但我肯定不能看到正在使用的IO完成端口,多比较,线程池。

so after a bit of reading i saw that the reccomended way to do this was to use the Begin/End methods to delegate the work to io completion ports, thus freeing up the threadpool and yielding better performance. this doesn't seem to be the case... the performance is marginally better but i certainly can't see the io completion ports being used that much compared to threadpool.

我有一个旋转轮与送我可用的工作线程+完成端口的线程池的线程。完成端口总是非常低(最大值我所看到的是9使用),我总是使用大约120工作线程(有时更多:()我用的是开始/在HttpWebRequest的所有方法结束方式:

i have a thread that spins round and sends me the available worker threads + completion ports in the threadpool. completion ports is always very low (max i've seen is 9 used) and i'm always using about 120 worker threads (sometimes more :( ). i use the begin / end pattern for all methods in httpwebrequest:

开始/ EndGetRequestStream
开始/ EndWrite(流)
开始/ EndGetResponse
开始/ EndRead(流)

Begin/EndGetRequestStream Begin/EndWrite (Stream) Begin/EndGetResponse Begin/EndRead (Stream)

我是这样做的权利我失去的东西,我可以使用(有时)高达2048 HTTP连接simultaenously(从netstat中输出) - ???为什么会完成端口号是如此之低。

am i doing it right? am i missing something? i can use (sometimes) up to 2048 http connections simultaenously (from netstat output) - why would the completion port numbers be so low?

如果任何人都可以提供有关如何使用这个管理工作线程,完成端口做好,HttpWebRequest的这将非常感激!

if anyone could give some serious advice about how to do well with this managing worker threads, completion ports and httpwebrequest it would be hugely appreciated!

感谢,

皮特

编辑:.NET是这个合理的刀具可以吗?获得与.NET和System.Net栈工作httpconnections量高?它被建议使用类似WINHTTP(或其他一些C ++库),以及它的PInvoke从.NET,但是这不是我要特别做!再次,任何建议等等!

is .NET a reasonable tool for this? can i get a high volume of httpconnections working with .NET and the System.Net stack? it's been suggested to use something like WinHttp (or some other C++ library), and pInvoke it from .NET, but this isn't something i especially want to do! again, any advice etc!

推荐答案

我的理解是,你不占用一个I / O完成端口所有的是在一个异步请求是优秀的时间 - 这只是忙时,数据已返回和相应的线程上正在处理中。希望你没有的非常的很多工作中的回调,这就是为什么你没有在任何一个时间很多使用的端口做。

The way I understand it, you don't tie up an I/O completion port all the time that an asynchronous request is outstanding - it's only "busy" when data has been returned and is being processed on the corresponding thread. Hopefully you don't have very much work to do in the callback, which is why you don't have many in-use ports at any one time.

您的实际的越来越表现不佳有关系吗?是您值得关注的只是低的数字?你得到你所期望的吞吐量是多少?

Are you actually getting poor performance though? Is your cause for concern merely the low numbers? Are you getting the throughput you'd expect?

有一个问题,你的可能的有是任何一个主机的HTTP连接池比较小。如果你有数百个请求在同一台机器,那么在默认情况下只有2个请求将的实际的可同时做,以避免拒绝服务攻击的主机有问题(并获得备存─的好处活)。您可以以编程方式或使用的app.config增加。当然,这可能不是你的情况的问题,或者是因为你已经解决了这个问题,或者因为所有的请求都以不同的主机。 (如果netstat的是显示2048的连接则是不健全的坏。)

One problem you may have is that the HTTP connection pool for any one host is relatively small. If you have hundreds of requests to the same machine, then by default only 2 requests will actually be made at a time, to avoid DoS-attacking the host in question (and to get the benefits of keep-alive). You can increase this programmatically or using app.config. Of course, this may not be an issue in your case, either because you've already fixed the problem or because all your requests are to different hosts. (If netstat is showing 2048 connections then that doesn't sound bad.)

这篇关于HttpWebRequest和I / O完成端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆