长轮询真的比定期 ajax 轮询更好吗?

发布于 2024-09-08 19:50:25 字数 96 浏览 0 评论 0原文

长轮询的开销是建立 http 连接,而且在服务器端,Java EE 服务器必须保存大量挂起的请求。

对于间隔为 10/20 秒的定期轮询,它会比长轮询效果更差吗?

The overhead for long polling is http connection establishment, also on server side the Java EE server has to hold a lot of suspended requests.

For periodic polls with 10/20 seconds interval, it will work worse than long polling?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦妄 2024-09-15 19:50:25

这取决于多种因素:

  • 发出新请求对客户端、服务器和网络的成本有多大?在某些情况下,服务器可能能够比“过去 20 秒内有任何结果”(来自客户端)更轻松地处理“这是一个新结果 - 将其推送给任何关心的人”(来自后端)。同样,通过 3G 网络建立新连接可能比维持现有连接更昂贵。
  • 立即获得结果有多重要? (例如,考虑一下聊天应用程序。)

(毫无疑问还有其他应用程序......)

It depends on various things:

  • How expensive is it on your client, server and network to make a new request? In some cases, the server may be able to handle "here's a new result - push it to anyone who cares" (from the backend) more easily than "have there been any results in the last 20 seconds" (from the client). Likewise new connections over a 3G network may be more expensive than keeping an existing one going.
  • How important is it to get immediate results? (Think about a chat application, for example.)

(And no doubt there are others...)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文