Is there a way to specify a different session store with Tomcat?

Tomcat (version 5 here) stores session information in memory. When clustering of this information is periodically transmitted to other servers in the cluster to synchronize the situation. You can use a database repository to make sessions persistent, but this information is also recorded periodically and is used only to restore failure, and not to replace sessions in memory.

If you do not want to use sticky sessions (our configuration does not allow this, unfortunately), this causes a problem of session synchronization.

In other languages, web frameworks tend to allow you to use the database as your primary session repository. Although this poses a potential scaling problem, it makes session management very simple. I am wondering if there is a way to force tomcat to use the database for sessions this way (technically this will also eliminate the need for any clustering configuration in tomcat server.xml).

+4
source share
4 answers

There is definitely a way. Although I strongly voted for sticky sessions - it saves so much load for your servers / database (unless something works) ...

http://tomcat.apache.org/tomcat-5.5-doc/config/manager.html contains information on setting up and configuring SessionManager for Tomcat. Depending on your specific requirements, you may have to implement your own session manager, but this starting point should provide some help.

+3
source

Take a look at Terracotta , I think it can solve your scaling problems without significant modification to the application.

+2
source

I have always been a fan of the Rails session technique: I saved sessions (encrypted + encrypted + signed) in a user cookie. This way, you can perform load balancing in your heart, rather than worry about sticky sessions or get into the database for your session data, etc. I'm just not sure that you can easily implement this Java application without any kind of rewriting of your session access code. In any case, just a thought.

+2
source

Another alternative might be memcached-session-manager , a memcached session recovery solution and session replication solution for tomcat 6.x / 7.x. It supports both sticky sessions and non-sticky sessions.

I created this project to get maximum performance and reliability and to be able to scale by simply adding more tomcat and memcached nodes.

+2
source

Source: https://habr.com/ru/post/1276804/


All Articles