News for hackers. Stuff that matters.
Re:10 000 concurrent real-time connections to Django by stefantalpalaru on Tuesday March 26, 2013 @07:14PM (#5446674)
The C10K problem[1] is about real clients accessing real web servers, not about writing short strings over WebSocket.

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).

[1] http://www.kegel.com/c10k.html

Re:10 000 concurrent real-time connections to Django by mYk on Tuesday March 26, 2013 @07:21PM (#5446696)
The C10k problem was originally about serving static files -- quoting the page you linked to: "take four kilobytes from the disk and send them to the network".

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.

Re:10 000 concurrent real-time connections to Django by StavrosK on Wednesday March 27, 2013 @06:51AM (#5448661)
By "implemented", do you mean "contributed to trunk", or "used it in my application"? If the former, thanks, if the latter, I was under the impression that it was on by default in 1.5?
Re:10 000 concurrent real-time connections to Django by stefantalpalaru on Wednesday March 27, 2013 @07:48AM (#5448808)
Looks like it will be available in the next (1.6?) release[1].

[1] https://docs.djangoproject.com/en/dev/ref/databases/#persist...

Re:10 000 concurrent real-time connections to Django by StavrosK on Wednesday March 27, 2013 @07:52AM (#5448821)
Oh right, 1.5 and earlier. I misread that, thank you.
Re:10 000 concurrent real-time connections to Django by stefantalpalaru on Tuesday March 26, 2013 @07:38PM (#5446756)
Static files are no longer a problem thanks to Varnish or nginx. And this is Django, after all, so please focus on dynamic content performance.

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!

Re:10 000 concurrent real-time connections to Django by mYk on Tuesday March 26, 2013 @07:45PM (#5446785)
Yes, I'm just referring to C10k because this demo uses a technique originally created to solve C10k.

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.

Re:10 000 concurrent real-time connections to Django by calvinx on Wednesday March 27, 2013 @01:46AM (#5447999)
Awesome stuff!
Re:10 000 concurrent real-time connections to Django by raverbashing on Wednesday March 27, 2013 @06:49AM (#5448658)
Well, about PgBouncer, I believe this tells more of PostgreSQL than of Django + psql libraries

(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)

Re:10 000 concurrent real-time connections to Django by stefantalpalaru on Wednesday March 27, 2013 @07:46AM (#5448798)
It's not PostgreSQL's fault that Django closes the connection after each request explicitly (see close_connection() for what was done before 1.6):

[1] https://github.com/django/django/blob/master/django/db/__ini...

Re:10 000 concurrent real-time connections to Django by raverbashing on Wednesday March 27, 2013 @09:57AM (#5449377)
I understand that, and I'm not saying that there aren't several issues in Django (but some are getting better)

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

Re:10 000 concurrent real-time connections to Django by vampirechicken on Tuesday March 26, 2013 @07:47PM (#5446796)
Why would you insist on creating and destroying a db connection on each request? We stopped doing that decades ago.
Re:10 000 concurrent real-time connections to Django by jaytaylor on Tuesday March 26, 2013 @08:16PM (#5446926)
Django hasn't stopped insisting on that... v1.5 might have pooling, but it's taken them a long time to get connection pooling in.
Re:10 000 concurrent real-time connections to Django by obviouslygreen on Tuesday March 26, 2013 @08:42PM (#5447026)
Forgive my ignorance, but isn't this the point of something like pgpool? I didn't think connecting to a connection pool would be as expensive as connecting to the database itself (if it is, then my next question would be: What's the point of a connection pool? Because clearly I've missed something one way or the other).
Re:10 000 concurrent real-time connections to Django by jaytaylor on Tuesday March 26, 2013 @09:59PM (#5447310)
Yes, but pgpool isn't always an option. If you use Heroku's Postgres service, you do not have sufficient privileges to run the commands to attach to software like pgpool.

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.

[0] https://github.com/gmcguire/django-db-pool

Re:10 000 concurrent real-time connections to Django by obviouslygreen on Wednesday March 27, 2013 @01:03AM (#5447896)
Understood, thank you for the clarification.
Re:10 000 concurrent real-time connections to Django by talmirza on Tuesday March 26, 2013 @11:47PM (#5447687)
You can still us pg_pool with heroku.
Re:10 000 concurrent real-time connections to Django by stefantalpalaru on Wednesday March 27, 2013 @07:51AM (#5448818)
Yes, connecting repeatedly to pgpool is less expensive than doing it directly to postgres. Not having to connect repeatedly to anything is even better.
Re:10 000 concurrent real-time connections to Django by taude on Wednesday March 27, 2013 @09:10AM (#5449149)
Wow. I'd just have assumed that connection pooling was default in all these modern web frameworks. I guess this is one area where Enterprise means you get what you pay for? Example: ODBC connection pooling with ASP pages back in the late '90s.
Re:10 000 concurrent real-time connections to Django by the_mitsuhiko on Wednesday March 27, 2013 @09:41AM (#5449293)
Connection pooling in postgres can actually be counter productive with high concurrency. Postgres scales very badly to high number of connections.