10 000 concurrent real-time connections to Django
github.com
github.com
Also, it's fun.
You could build 95% of an application with the traditional request-response model and add the 5% of real-time featurs with a system similar to my demo.
(Of course, given your opinions on Django, I don't recommend you build anything with it.)
We've implemented some SSE based solutions lately with gevent & nginx in front of django, and it's been great to keep it all in the django family.
Maybe switching to py3k has some value after all... =)
All those things by themselves could be considered trivial and could be gotten from many individual libraries - the level of integration and polish you encounter with Django is anything but trivial though and takes real time and effort.
I've recently had to make a choice for a Python based application platform/environment and have chosen Django (again) despite having no use for the ORM and ORM-using contrib modules. Simply because all the other things are there and work together beautifully without me spending any time on code that is not directly related to my goals.
In the long run they might build tulip-awareness into the ORM.
For that matter I start Tornado servers with management commands just for convenience...
This blocks in a separate thread leaving the event loop to handle other tasks.
In practice, debugging is an unpleasant experience. If you're doing anything slightly out of the ordinary, you should take care.
I'll associate "C10K" and "Django" when I'll see a dynamic web page being served using the template system, the standard middleware and the ORM (with the default behavior of creating and destroying a database connection for each request).
The demo could certainly be extended to send larger amounts of data -- left as an exercise for the reader.
I'm not sure to understand your second paragraph -- if I used this system in a real application, I would serve the pages with the traditional handler (with template rendering, middleware, etc.) and then exchange messages over the websocket. These are different roles.
Regarding database connections, the default behavior isn't the one you're describing any more; I implemented persistent connections in Django a few weeks ago.
I'm glad to hear that Django managed to get persistent db connections after years of "just use PgPool/PgBouncer". Keep up the good work!
Reaching 10 000 connections wasn't difficult in this case; it was just a matter of tuning a few system parameters. Exploring the APIs and studying how they can fit together was much more interesting, and sometimes challenging.
(After all it will still open and close connections for Django but keeps them open for psql)
Now, for serving 10k connections with template libraries and middlewares and ORM, out of the box? Serving dynamic content for each connection? Impossible =)
Not without some kind of caching (but you can do that with the help of a middleware)
[1] https://github.com/django/django/blob/master/django/db/__ini...
What I'm saying is that with PgBouncer you have Django <> PgBouncer <> Postgresql, right?
So what PgBouncer is doing (dealing with several open/close connections) maybe could be done better inside PostgreSQL
[1] https://docs.djangoproject.com/en/dev/ref/databases/#persist...
The only way we were able to get connection pooling working in django 1.3/1.4 was to use django-dbpool[0]. It works okay, but is still pretty sketchy compared to the connection pooling libraries available for the JVM like BoneCP or C3P0.