CCSab
CCSab

Reputation: 1475

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.

Upvotes: 10

Views: 2960

Answers (2)

Malcolm Box
Malcolm Box

Reputation: 4036

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.

Upvotes: 2

Mike
Mike

Reputation: 7831

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

Upvotes: 1

Related Questions