Comet VS Ajax 轮询
我需要创建一个像 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
延迟并不是唯一的问题。 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).
@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).
如果延迟不是问题,那么 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)