Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX Polling vs. WebSockets Mobile Performance

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.

like image 287
CCSab Avatar asked Jun 08 '11 19:06

CCSab


2 Answers

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.

like image 109
Malcolm Box Avatar answered Nov 15 '22 20:11

Malcolm Box


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

like image 35
Mike Avatar answered Nov 15 '22 20:11

Mike