2008-01-18

django-evserver - Asynchronous server for Django

I mentioned the idea in previous post about asychronous wsgi.

Now we have working example of simple chat application. The chat is nothing special, but it's made in Django! To make this possible I created special server, django-evserver. It's quite light wrapper to libevent http layer (several hundred of lines in python/ctypes).

Using this technology it's now possible to create asynchronous WSGI applications. Currently I implemented the Comet javascript library and some wrappers for Django views, to make easier writing comet applications in Django.

Here is how example chat application evserver-chat looks like:

The code is commited to code.google.com, maybe in future I'll write some more code and documentation. For example it could be interesting how I used named fifos (mkfifo) to pass events.

16 comments:

Niels Sandholt Busch said...

Looks sweet. Thanks. I'll give it a try some day soon.

zgoda said...

Definitely worth looking. I'll try to abuse it a bit. ;)

Arnar Birgisson said...

Excellent initiative! I'll try it out for sure when I find time..

I've been meaning to write a libevent based WSGI server myself for a while. Guess now I don't have to :)

Mathieu Ravaux said...

Very interesting, can't wait to test it !

Timothy said...

Hahaha, you are aware this already exists right? When you think Asynch and python, don't you think twisted?

Twisted web2 has a wsgi server
http://twistedmatrix.com/documents/current/api/twisted.web2.wsgi.html

Glyph Lefkowitz said...

Not only does twisted.web2 support WSGI - there's already a COMET chat application demo for Twisted (using Nevow) :). It's even on Blogger.

Have a look here at Duncan's blog.

Esaj said...

The response time looks pretty impressive.

majek said...

zgoda said: Definitely worth looking. I'll try to abuse it a bit. ;)
Feel invited :)

Timothy said: Hahaha, you are aware this already exists right?
In previous post I analyzed other possibilities of comet for python. I'm not interested in Twisted for political reasons, it looks too much like Java for me. Next reason is that django-evserver is 500 python lines in server file (mostly ctypes wrapper to libevent), and about 100 lines for Django helpers. I suggest that Twisted uses a bit more LOC and that it's a bit slower. But of course the idea of async WSGI is nothing new.

Piotr Maliński said...

I played with Orbited. Their examples may have problems, but I made it working without "any" problems :) I wrote a tutorial about it :)

majek said...

Piotr Maliński said: I played with Orbited.

Nice to hear this! As far as I know, Orbited needs Pyevent, which works only for Python 2.4. But indeed it seems that we both try to achieve simmilar thing :)

Piotr Maliński said...

Python 2.5.1 and it works :) on Gentoo amd64 even :)

Michael Carter said...

Actually, Orbited 0.3.2 and 0.4.0aplah1 don't require pyevent anymore. It can be used optionally to make the network IO more efficient, but it will also work with the python-epoll module, or plain old poll or select.

majek said...

Michael Carter said: Pyevent can be used optionally to make the network IO more efficient, but it will also work with the python-epoll module, or plain old poll or select.

It means that you implemented full http stack in python which is very interesting. In django-evserver I used libevent stack, which was buggy :P

New orbited seems to be worth looking.

Bogdan said...
This post has been removed by the author.
Bogdan said...

This looks very interesting. However, I'm having a hard time trying to host this using apache and mod_python. Is this the proper way? Can you post a (very) small tutorial?

majek said...

> This looks very interesting. However,
> I'm having a hard time trying to host
> this using apache and mod_python. Is
> this the proper way? Can you post a
> (very) small tutorial?

No. It must be executed as a standalone application. The project is currently abandoned, I'm waiting for somebody to pay me for developing this.