加速 Socket.IO
当我在 Socket.IO 中监听客户端连接时,似乎有 8-9 秒的延迟,因为它回退到 XHR。对于大多数用途来说这太慢了,因为我使用 Socket.IO 将数据推送到用户的新闻提要,并且 8 或 9 秒内可能会发生很多事情。
有什么办法可以加速这种失败吗?
编辑:
部署到 Nodejitsu 的 VPS 后,我再次尝试了此操作,套接字连接几乎是立即的(足以让用户不会注意到)。我只在本地机器上经历过这种情况。所以问题实际上可能是:为什么我的本地计算机上速度这么慢?
When I listen for a client connection in Socket.IO, there seems to be a latency of 8-9 seconds as it falls back to XHR. This is too slow for most purposes, as I'm using Socket.IO to push data to users' news feeds, and a lot can happen 8 or 9 seconds.
Is there any way to speed up this failure?
EDIT:
After deploying to Nodejitsu's VPS I tried this again and the socket connection was nearly immediate (enough that a user wouldn't notice). I'm only experiencing this on my local machine. So the question may actually be: why is it so slow on my local machine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有有关本地设置的更多信息,这个问题几乎不可能回答,但有趣的是,您正在故障转移到 XHR。以下问题可能可以解释为什么它会故障转移到 XHR,但如果您在发布后能够成功使用相同的浏览器,则无法解释。
Socket.io 恢复到 XHR / JSONP 轮询没有明显的原因
我读到的另一个潜在问题是您的浏览器缓存了不正确的传输方法。您可以尝试清除浏览器缓存并重新连接,看看是否可以解决问题。
https://groups.google.com/group/socket_io/browse_thread/thread/e6397e89efcdbcb7/a3ce764803726804
最后,如果您无法弄清楚为什么它不使用 WebSockets 或 FlashSockets,您可以尝试将它们作为选项从 socket.io 配置中删除,这样当您在本地开发时,您也许能够克服这种延迟至少为了更快的发展。
This question is almost impossible to answer without more information on your local setup, but it's interesting that you're failing over to XHR. The following question might explain why it's failing over to XHR, but not if you're able to use the same browser successfully once it's published.
Socket.io reverting to XHR / JSONP polling for no apparent reason
Another potential problem I've read about is that your browser has cached the incorrect transport method. You could try clearing your browser cache and reconnect to see if that gets around the problem.
https://groups.google.com/group/socket_io/browse_thread/thread/e6397e89efcdbcb7/a3ce764803726804
Lastly, if you're unable to figure out why it's not going using WebSockets or FlashSockets, you could try removing them as options from your socket.io configuration so that when you're developing locally, you may be able to get past that delay for quicker development at least.