AJAX Polling vs. WebSockets Mobile Performance
Asked Answered
F

2

10

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.

Flinders answered 8/6, 2011 at 19:12 Comment(3)
You may also want to look into the "comet" style ajax, where you open a connection from the client and leave it open for a decent amount of time (30 seconds or so), so the server can send a response as soon as an event happens. If nothing happens in that 30 seconds, the server just sends a "nothing happened" response, the client doesn't change anything, and sends it's request to the server again.Rooted
Socket.io breaks a websocket connection as soon as there is a break from the client, so there's constant communication. I'd have to guess maintaining constant communication would use more resources and therefore battery life as compared to a intermittent polling.Patrilineal
Would using a comet style ajax require an additional server running in parallel to the one serving up the site?Flinders
E
2

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.

Erine answered 8/9, 2011 at 14:9 Comment(0)
M
1

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

Mamie answered 24/6, 2011 at 5:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.