开发者

way to fix number of concurrent sessions allowed at app level. django

How can I fix number of concurrent sessions allowed at app level? B开发者_StackOverflowasically 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.


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


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:

  • http://docs.djangoproject.com/en/dev/topics/http/sessions/#clearing-the-session-table


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜