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.

CCSab
  • 1,455
  • 3
  • 16
  • 27
  • 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. – uscere90 Jun 08 '11 at 19:14
  • 1
    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. – Robert Jun 08 '11 at 19:19
  • Would using a comet style ajax require an additional server running in parallel to the one serving up the site? – CCSab Jun 08 '11 at 19:25

2 Answers2

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.

Malcolm Box
  • 3,968
  • 1
  • 26
  • 44
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

Mike
  • 7,769
  • 13
  • 57
  • 81