问题描述
我正在建立一个实时网络应用程序据我所知,最受欢迎的选择是短轮询和长轮询。测量一个优于另一个有什么优点和缺点?
I'm building a real-time web application As far as I know, the most popular choices are short-polling and long-polling. What are the advantages and disadvantages might there be for measuring one over the other?
推荐答案
-
短轮询(又名基于AJAX的计时器):
Short polling (a.k.a. AJAX based timer):
优点:更简单,而不是服务器消耗(如果请求之间的时间很长)。
缺点:如果您需要在服务器事件发生且没有延迟时收到通知,则会很糟糕。
()Pros: simpler, not server consuming (if the time between requests is long).
Cons: bad if you need to be notified WHEN the server event happens with no delay.Example (ItsNat based)长轮询(也就是基于XHR的Comet)
Long polling (a.k.a. Comet based on XHR)
优点:当服务器事件发生且没有延迟时,您会收到通知。
缺点:使用更复杂和更多的服务器资源。
(基于ItsNat)Pros: you are notified WHEN the server event happens with no delay.Cons: more complex and more server resources used.Example (ItsNat based)
这篇关于实时Web应用程序的短轮询与长轮询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!