Comet VS Ajax 轮询

发布于 2024-09-04 10:05:39 字数 161 浏览 6 评论 0原文

我需要创建一个像 Facebook 聊天一样的聊天。

对于 Comet,我需要更多内存来保持连接。

使用 Ajax 轮询时,如果我每 3-4 秒发送一次请求,就会出现延迟问题。

那么...如果延迟(3-4 秒)并不重要,那么 Ajax 轮询是否更适合我的情况?

I need to create a chat like facebook chat.

With Comet I need more memory to keep the connection.

With Ajax polling there is a latency problem if I send request every 3-4 seconds.

So... If the latency ( 3-4 seconds ) doesn't matter, Is Ajax Polling better for my case ?

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

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

发布评论

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

评论(3

以歌曲疗慰 2024-09-11 10:05:39

延迟并不是唯一的问题。 COMET(长轮询)“节省”您的流量 - 当您使用轮询时,您无法知道服务器上是否有更改,因此某些调用可能只是浪费流量和资源(例如,即使没有人聊天时,您每 3-4 秒就拨打一次电话)。对于 COMET,您通常只需调用一次即可从服务器获取更新(命中率 100%)。

Latency is not the only problem. COMET (long-polling) "saves" your traffic - when you use polling, you cannot know, if there were changes on the server, so some of the calls may be just a waste of traffic and resources (e.g., even if no one's chatting, you're making calls every 3-4 seconds). In case of COMET, you generally need one just call to get an update from the server (with 100% hit rate).

探春 2024-09-11 10:05:39

@Vasil:“你可以保留数百万个打开的连接”

看看 这个问题

以及关于NIO 相对 IO 的虚假优势

iobound 文章只是显示 IO 优于 NIO,是的,IO 在 NIO 之前就耗尽了内存(顺便说一句,作者没有尝试用较低的值来减少堆栈内存)。

@Vasil: "you can keep millions of opened connection"

Take a look to this problem

And regarding the false superiority of NIO over IO.

The iobound article just shows IO outperforms NIO and yes IO goes out of memory before NIO (by the way, the author has not tried to reduce the stack memory with a lower value).

誰認得朕 2024-09-11 10:05:39

如果延迟不是问题,那么 AJAX 可能会更好。如果您不是非常非常小心,Comet 在维护同一客户端/服务器对之间的多个连接时可能会遇到问题。 (参考)

If latency isn't an issue then AJAX is probably better. Comet can encounter problems maintaining multiple connections between the same client/server pair if you're not very, very careful. (Ref)

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