AJAX 轮询与 WebSockets 移动性能

发布于 2024-11-14 06:57:50 字数 338 浏览 2 评论 0原文

我目前正在 Django 中开发一个网站,我想为其实现某种准实时更新系统。

由于这个网站是为移动设备设计的,我想知道定期轮询服务器的变化(比如每 5 秒)和使用某种 Websocket 实现 ala http://codysoyland.com/2011/feb/6/evented-django -part-one-socketio-and-gevent/

就电池寿命而言,差异可以忽略不计吗?从代码角度来看,AJAX 实现似乎也会更简单。

I'm currently developing a site in Django that I'd like to implement some sort of quasi-realtime update system for.

Since this site is intended for mobile devices, I was wondering what the performance comparison was between periodically polling the server for changes (say, every 5 seconds) and using some sort of Websocket implementation ala http://codysoyland.com/2011/feb/6/evented-django-part-one-socketio-and-gevent/.

With respect to battery life, is the difference negligible? Code-wise, it seems an AJAX implementation would also be simpler.

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

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

发布评论

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

评论(2

且行且努力 2024-11-21 06:57:50

答案是“这取决于”。如果您的目标是具有已知良好 Websockets 实现的移动设备,那么就这样做。目前,可能只有运行 iOS4.2 或更高版本的 iPhone/iPad 可能有很好的实现。

对于其他人来说,无论如何你都会进行民意调查,所以我建议沿着这条路走。

我已经完成了几个近乎实时的服务(<10 秒延迟),它们使用轮询工作得很好。我不会将它用于聊天引擎,但对于其他大多数事情来说它都很好。

The answer is "it depends". If you're targeting a mobile device with a known good websockets implementation then go that way. At the moment, that's probably only iPhone/iPad with iOS4.2 or later which might have a good implementation.

For everyone else, you're going to be doing polling anyway, so I'd say go down that route.

I've done several near-real time services (<10s latency) that work fine using polling. I wouldn't use it for a chat engine, but for most everything else it's fine.

谁的新欢旧爱 2024-11-21 06:57:50

就电池而言,我认为两者都不会产生很大的影响。我会使用socket.io,因为你只使用socket.io,它会尝试使用websockets,如果浏览器不支持它们,则回退到ajax请求

battery wise I don't think either will make a big difference. I would use socket.io though since you just use socket.io and it will try to use websockets and if the browser does not support them fall back to ajax requests

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