开发者

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

开发者 https://www.devze.com 2023-01-16 14:54 出处:网络
My django-powered site sits behind a Apache-based loadbalancer. There also is a server handling static file requests, but that\'s simple.

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

精彩评论

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

关注公众号