开发者

Running django site in multiserver environment - how to handle sessions?

My django-powered site sits behind a Apache-based loadbalancer. There also is a server handling static file requests, but that's simple.

What bothers me is how to handle a user who can be thrown to any of the application servers by the load-balancer? They all share the same DB-cluster (is it smart? Or should I separate it here too?), so only thing I need to care about is the session.

Right now the sessions are stored in memory, for performance. I would rather keep them there, so what I'd need to do is make sure that the same user would always hit the same app-server.

A few simple solutions came to my mind.

1) make it IP-based. Lets say, odd IP numbers hit server A and even numbers hit the B. But what if a user is behind a proxy or has IP that changes often?

2) When a request hits the load-balancing se开发者_开发知识库rver, I could try to check it for cookies and see which server should handle that. Is it possible / does make sense?

3) I know J2EE solutions, using mod_proxy_ajp, handle those kind of situations, although I got no idea what happens behind the scenes there. Could something from there be used for Django?

Or maybe there is some other way to clusterize Django for that?


You could configure a cluster of memcached and setup your django to use it for session storage: http://docs.djangoproject.com/en/dev/topics/http/sessions/#using-cached-sessions

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜