0

I have 2 Tomcats working in the loadbalancing with sticky_sessions=false. So I need "Session persistance" across the Tomcats. Tomcat documentation says there are 3 ways:

  1. Tomcat Clustering
  2. Persistance Manager + Shared Dir
  3. Persistance Manager + SQL Storage

Clustering doesn't fit me, because in the documentation it is written, that to configure it sticky_sessions should be true.

I tried Persistance Manager, but it looks like it also doesn't work, as it persists session only after some timeout, so with sticky_session=false it is not working.

Can Persistance Manager persists sessions immediately?

I read about memcached-session-manager, but it looks like 3d party solution, so I am afraid to use it. Is it the only solution?

1 Answers1

0

You don't need session persistence; you can do it with clustering, too. Sticky sessions are a good idea in general because they fix a lot of potential race conditions (or, alternatively, performance issues).

You can enable clustering without sticky sessions. But you probably want to use stick sessions with clustering unless there is some compelling reason to disable it. (Remember, fail-over will still occur with sticky sessions enabled.)

The problem with the PersistentManager is that you can't guarantee that the sessions will be updated in the store in a timely manner. Have a look at the maxIdleBackup configuration attribute for your PersistentManager. It may give you some clue of how to tune the persistence.

PersistentManager is really there in order to solve a different problem: handling huge numbers of long-lived sessions with limited memory. Think about using something like Amazon.com, where they remember what you have in your "shopping cart" for weeks and weeks. You could do that in a lazy way with the "cart" being stored in the session persisted to a DB or file.

If you really want to share sessions across multiple servers, clustering is your best option. There are some great presentations available on the Tomcat web site that cover clustering.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
  • The problem 1) Tomcat documentation says "Make sure that your loadbalancer is configured for sticky session mode.", and doesn't say how to configure "sticky_session=false" with synchronous clustering. So it looks like it is not supported officially. 2) With sticky_session=true we do not need all this complexity, it is ok to loose session if one of the servers failed in our use-case. – Dmitrii Stebliuk Apr 22 '16 at 09:17
  • If it's okay to lose a session if one of the servers fails, then you don't need clustering *at all*. It's not clear to me if it's okay for your users to lose their sessions. As I said, sticky sessions reduce the possibility of race-conditions where your user is making requests to arbitrary servers before the session information can be updated across the entire cluster. – Christopher Schultz Apr 25 '16 at 00:59
  • For users of my application it is not okay to loose session every request, but it is tolerant on some fail (hardware fail, tomcat fail). Race-conditions only occurs on asynchronous session replication, for sure because of that I need synchronous session-replication (or clustering). The problem Tomcat documentation does not say how to configure it synchronously. – Dmitrii Stebliuk May 02 '16 at 07:04
  • If session-loss is acceptable in extreme cases (i.e. failure), then forget about clustering and just enable stick-sessions. Your application run much faster that way, and there will be fewer opportunities for errors. – Christopher Schultz May 04 '16 at 15:42