views:

23

answers:

3

Hi, How can I fix number of concurrent sessions allowed at app level? Basically I want a limit to how many concurrent requests to this url to keep the server from getting congested. I guess some middleware hack?

Thanks.

A: 

Django stores session information in the database by default. You could use a middleware, which checks the number of rows (coarsly speaking) in that table. Keep in mind that django won't purge expired sessions from the DB automatically.

On clearing the session table:

The MYYN
+1  A: 

Don't do this in django, but in Apache / nginx / whatever webserver you have in front of Django. They have specific modules exactly for such tasks.

A possible solution for Apache would be: mod_limitipconn2 - http://dominia.org/djao/limitipconn2.html

mawimawi
A: 

You're not asking about sessions, you're asking about requests. What you want is known as throttling. However, it would be quite difficult to do it inside the app, because Apache manages multiple processes and threads, so you'd need some external process to keep track of these in order to enable the throttling.

Basically, this sort of thing is best done within Apache itself, by something like mod_throttle.

Daniel Roseman