Note: Eric is one of the founders of convore (see the djangocon eu 2011 group on convore). His talk is on converting a django site to the realtime age: does the django heart stay in place or is it replaced with something “more current” like node.js?
In the end, he told his story as a fairy tale. Entertaining and slick. Good job!
At a certain time he thought about writing a shiny new social photo website. All the cool sites were about social photo stuff. So he build one. And it became popular! And slow. So caching to the rescue. It helped. For a while. It became even more popular. Social photos mean frantic reloading of webpages. So it became slow again. Full-page reloads. Even expiry headers didn’t help.
But the site grew and grew. And grew and grew. And again the site was hitting the borders of technology. Something new was needed, again. He tried long polling. That looked to help a bit, but he ran into problems with the limited number of available django threads/processes. Would this mean the end of django and the start of node.js?
Well, that harsh step wasn’t necessary. Only that one single endpoint was strange compared to the rest. So that endpoint was separated out for implementation in a twister-style or co-routines-based part. Twister-style implementations are straightforward and explicit, but it becomes a hairy tangly mess easily. Co-routines (“eventlet”) look much more magical, but are simpler in the end. At least, he was used to threads, which look a lot like what co-routines end up as.
When trying to hook it all up, he discovered redis. That helped a lot in hooking up all the events and responses.
The advantage of the setup until this point: the hardest-hit part is heavily optimized and the rest of the code is relatively normal django code. It works quite well. A good example for how to set up a real-time website.
But he wasn’t satisfied yet. He contemplated. He figured out that this whole setup was actually just an implementation of sockets over http. So a bit of searching was in order. Hey, there’s “web sockets”. Sounds great! Till he read more about it and his enthousiasm waned. Web sockets are a mess. Security concerns at firefox that removed the support. Microsoft that won’t support it. Inconsistent implementation.
But… he figured it was OK anyway. Client-side detection for web socket support to use it when available. Extra functionality on the server side to support it. Only to run into ngnix problems. It doesn’t support web sockets and anyway it has problems with keeping connection alive to internal proxies. He solved it (note: but I didn’t get what the solution was, something with ‘http proxy’ in its name…).
Time for more features! Group support, commenting on friends’ photos. But every new feature meant a dual implementation: on the server and on the client. Two sources for bugs. This is a problem he’s not solved yet. Right now the site works pretty fine, but there’s room for improvement.
Three main points he wants us to remember:
A quick word about socket.io. It tries to bridge the various ways in which you can run real-time web apps, abstracting it away a bit. It looks ok, but there are problems that need solving. But interesting to check out nonetheless.
My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.
Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):