Using tomcat in cyclic mode

I want to run my tomcat instances in a configuration where requests are submitted to multiple instances of a tomcat instance through round robin. I do not want to use any internal cluster manager.

As far as I see, if each request will be served by different cats, an unknown sessionId will go to tomcat, so it will be forced to create a new session and overwrite the old sessionId. Therefore, a new session will be created for each request. This seems to be a lot of overhead.

I think this is right? Is there any way to disable tomcats session management?

Regards, Michael

+4
source share
3 answers

Basically, you have two options:

1) Replicate your sessions so that they become available to any Tomcat node. Solutions: Tomcat Cluster , memcached-session-manager , possibly others.

2) Use a load balancer and do sticky sessions. The first requests will be routed randomly on a round-robin basis, but subsequent requests will stick to the same server. Solutions: mod_proxy , hardware traffic dispatchers.

The disadvantage of the first option is that session replication is expensive, not very reliable, and often requires Serializable β€” only the data that needs to be placed in the session.

The disadvantage of the second approach is that if you disable Tomcat for maintenance, users will be forced to log in again.

You mistakenly believe that "a new session will be created for each request." A new session will be created only if it was not created earlier on the same server or was created, but has already expired.

+3
source

We typically used Tomcat behind the Apache web server with mod_jk to balance the load of requests across Tomcat instances.

With sticky sessions, the user will only receive the session upon first request and will subsequently be sent to Tomcat, from where his session starts. Thus, there is no need to replicate sessions in all Tomcats, and requests will also be distributed through Tomcats.

Of course, this does not guarantee the kind of circular rotation you requested.

+1
source

A session will only be created after your code requests a session, so if your application does not require a session, you simply don’t get it. Checkout the getSession () section of the HttpServletRequest

http://download.oracle.com/javaee/5/api/javax/servlet/http/HttpServletRequest.html#getSession(boolean )

I'm not sure if there is a way to replicate a session through different tomcat instances, but if you need some user state without a session, you can use cookies instead.

EDIT: if you need to repeat the session, perhaps you can start by reading this tomcat document. http://tomcat.apache.org/tomcat-5.5-doc/cluster-howto.html

-1
source

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


All Articles