AJAX 轮询与 WebSockets 移动性能
我目前正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案是“这取决于”。如果您的目标是具有已知良好 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.
就电池而言,我认为两者都不会产生很大的影响。我会使用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