Share Sessions between tomcat instances (without using Sticky Sessions)

后端 未结 4 1219
情话喂你
情话喂你 2021-02-01 05:28

I\'m going to have 3 Tomcat servers and a Load Balancer that dispatches the requests without using \'sticky sessions\'.

I want to share sessions\' data between the serve

4条回答
  •  执笔经年
    2021-02-01 05:59

    Storing your session state outside of the app servers (Tomcat in your case), is a very common and recommended configuration for large scale websites. This is usually done in pursuit of an architecture style called Shared Nothing.

    You can store your state in several different places: db, memcached, commercial replicated cache, etc. They all work with different mixtures of trade offs. Personally, I've had great success with memcached. Memcached is extremely fast and stable.

    Generally, I opt for simplicity and use N memcache servers where N>1, say 2. As users log in, the app servers flip a coin to decide which server stores the users state. The cookie sent to the browser includes information to know which memcache server to route to from then on. Subsequent requests from the browser fetch state from the appropriate memcache server on each request. Should a memcache server fail, the user will have to login again as the app servers reselect a new server, but that is extremely rare.

提交回复
热议问题