HTTPWebRequest 类有多快?
我想知道,与自行编写的 HTTP-Response 解析器相比,HTTPWebRequest 的速度有多快。
我知道 HTTPWebRequest 类能够使用带有管道的持久 TCP 连接(默认情况下启用管道)。还可以设置缓存和压缩的值。
响应的解析可能永远不是瓶颈,但这只是出于我的好奇心:HTTPWebRequest 类是否会产生“不必要的”开销?
I was wondering, how fast the HTTPWebRequest is in comparision with a self-written parser for the HTTP-Response.
I know the HTTPWebRequest class is capable of using a persistent TCP connection with pipelining (pipelining is enabled by default). It's also possible to set values for caching and compression.
The parsing of the response is probably never the bottleneck, but just for my curiosity: Does the HTTPWebRequest class produce "unnecessary" overhead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不知道自己编写的解析器是什么,就不可能对您的问题给出量化的答案。也就是说,您可能能够编写一个比
HTTPWebRequest
更快的解析器,如果(例如):如果您可以限制场景,您或许能够超越
HTTPWebRequest
,因为它必须能够处理任何有效响应,而自定义解析器必须只能处理它期望的场景。也就是说,请记住,您所编写的内容将不是一个 true HTTP 响应解析器,而是处理有效响应的严格子集的东西。判断是否存在可以避免的开销的唯一方法是编写自己的(子集)解析器并将其性能与内置解析器的性能进行比较。
Without knowing what the self-written parser is, it's not possible to give a quantified answer to your question. That said, you might be able to write a parser that is quicker than
HTTPWebRequest
, if (for example):If you can constrain the scenario, you may be able to outperform
HTTPWebRequest
as it has to be able to handle any valid response, whereas a custom parser has to only be able to handle scenarios it's expecting. That said, bear in mind that what you're writing won't then be a true HTTP response parser, rather something that handles a strict sub-set of valid responses.The only way you can tell if there's any overhead which you can avoid is by writing your own (sub-set) parser and comparing its performance to that of the in-built one.
我没有结论,但我认为这类问题应该由实际案例来激发。例如,HttpWebRequest 类是否会减慢您的解决方案?您是否使用某些探查器检查了其性能影响?
毕竟,关于此类优化问题有一句众所周知的话:过早的优化是任何软件开发的魔鬼。
我最好的建议是你应该关心其他事情,使用一个好的分析器并找出你的程序存在性能问题的地方(我确信 HttpWebRequest 不会成为问题!)。
I don't have a conclusion, but I believe this kind of questions should be motivated by an actual case scenario. For example, does HttpWebRequest class slowdowns your solution? Have you checked its performance impact using some profiler?
And, after all, there's a well-known sentence about this kind of questions regarding optimization: premature optimization is the devil of any software development.
My best suggestion is you should take care about other things, use a good profiler and find out where your program have performance issues (I'm sure HttpWebRequest won't be the problem!).