Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use orbited or gevent for integrating comet functionality into a django app

I have been working with Django for some time now and have written several apps on a setup that uses Apache 2 mod_wsgi and a PostgreSQL database on ubuntu.

I have aa app that uses xsendfile to serve files from Apache via a Django view, and also allow users to upload files via a form as well. All this working great, but I now want to ramp up the features (and the complexity I am sure) by allowing users to chat and to see when new files have been uploaded without refreshing their browser.

As I want this to be scale-able, I don't want to poll continually with AJAX as this is going to get very heavy with large numbers of users.

I have read more posts, sites and blogs then I can count on integrating comet functionality into a Django app but there are so many different opinions out there on how to do this that I am now completely confused.

Should I be using orbited, gevent, iosocket? Where does Tornado fit into this debate?

I want the messages also be stored on the database, so do I need any special configuration to prevent my application blocking when writing to the database? Will running a chat server with Django have any impact on my ability to serve files from Apache?

like image 466
Finglish Avatar asked Aug 15 '11 13:08

Finglish


2 Answers

I'd recommend using WebSockets for bidirectional realtime communication. Keep running Django as is and run a WebSocket server on another port. As far as your database blocking, yes, you'll need to keep that in mind as you write your WebSocket server and either use a non-blocking database driver, or address that in some way.

Client-side you'll want to use Socket.IO or web-socket-js to support flash fallback for older browsers which don't support flash.

For the server, I would lean towards gevent or tornado, personally. For gevent there is gevent-websocket and gevent-socketio, for tornado you get built-in WebSocket support and can use tornadio if you want to use Socket.IO. Eventlet and twisted both support WebSockets as well. There is also a pretty cool new project called autobahn which is built on twisted, and meinheld has WebSocket middleware you can use.

WebSockets are pretty exciting, and as such there are tons of great posts out there on the subject. I found these posts useful:

  • http://gehrcke.de/2011/06/the-best-and-simplest-tools-to-create-a-basic-websocket-application-with-flash-fallback-and-python-on-the-server-side/
  • http://codysoyland.com/2011/feb/6/evented-django-part-one-socketio-and-gevent/
  • http://toastdriven.com/blog/2011/jul/31/gevent-long-polling-you/
  • http://blog.jupo.org/post/8858247674/real-time-web-apps-with-django-and-websockets/
like image 134
zeekay Avatar answered Nov 11 '22 15:11

zeekay


Instead of Apache + X-Sendfile you could use Nginx + X-Accel-Redirect. That way you can run a gevent/wsgi/django server behind Nginx with views that provide long-polling. No need for a separate websockets server.

I've used both Apache + X-Sendfile and Nginx + X-Accel-Redirect to serve (access-protected) content on Webfaction without any problems.

like image 29
Daniel Eriksson Avatar answered Nov 11 '22 15:11

Daniel Eriksson