Vikram Palakurthi
Vikram Palakurthi

Reputation: 2496

P2P Hazelcast Session Replication for Tomcat6 Web Clustering - Session Synchronization Fails

I believe I am missing some configuration either on load balancing side or in tomcat, it would great if someone could help and provide the solution.

What am i trying to do?

  1. Setup two tomcat instances with P2P Hazelcast session replication for tomcat6 by referring to this guide
  2. I have placed the hazelcast-all-.jar, hazelcast-tomcat-sessionmanager-.jar and hazelcast.xml in the folder $CATALINA_HOME/lib/
  3. Updated the listener and the context configs as shown below
  4. Updated Tomcat Failover and the jvmRoute Parameter as shown below
  5. So far, i was able to bring up the tomcat instances which connect to each others hazelcast instances, I see that in the tomcat logs.
  6. The users connects to the load balancer and are routed to the balancer members - no issues here.
  7. But when I take one of the tomcat instance down to test failover and to make sure users who were connected to tom instance were able to continue to cat instance with the same session and without having to sign in again. But I believe the load balancer seems to be creating a new session and forces user to sign in again to establish a session with cat instance. I suspect it this but not sure.
  8. Or are the sessions not being replicated and synced in both hazelcast instances? - This is happening
  9. Do we have a client where I could monitor hazelcast sessions? - Now I do

I did refer to this issue which refers setting up hazelcast.sessionId instead of JSESSIONID but does not provide any specifics about how to.

Versions -

Apache Haus - 2.2.32 (for load balancing)
Hazelcast - 3.8.6
Java 8
Tomcat - 6.0.48
Session objects that need to be clustered are Serializable.
stickysession=JSESSIONID

Load Balancer Configuration

 <Proxy balancer://mycluster>
        BalancerMember http://IPAddress1:8080/app/  route=tom
        BalancerMember http://IPAddress2:8080/app/  route=cat
        ProxySet lbmethod=byrequests stickysession=JSESSIONID|jsessionid
 </Proxy>

    ProxyPass /app/ balancer://mycluster/ 
    ProxyPassReverse /app/ balancer://mycluster/

tom instance - server.xml

<Listener className="com.hazelcast.session.P2PLifecycleListener"/>
<Engine name="Catalina" defaultHost="localhost"  jvmRoute="tom">

tom instance - context.xml

<Manager className="com.hazelcast.session.HazelcastSessionManager" sticky=true/>

cat instance - server.xml

<Listener className="com.hazelcast.session.P2PLifecycleListener"/>
<Engine name="Catalina" defaultHost="localhost"  jvmRoute="cat">

cat instance - context.xml

<Manager className="com.hazelcast.session.HazelcastSessionManager" sticky=true/>

Update:

I believe the below is the same issue I have session sync failure

Upvotes: 0

Views: 726

Answers (2)

Vikram Palakurthi
Vikram Palakurthi

Reputation: 2496

I got it working with the below configuration. Figured it needed both jsessionid and hazelcast.sessionid, the session replication works great now.

<Proxy balancer://mycluster>
    BalancerMember http://IPAddress1:8080/app/  route=tom
    BalancerMember http://IPAddress2:8080/app/  route=cat
    ProxySet lbmethod=byrequests stickysession=JSESSIONID|jsessionid|hazelcast.sessionId
</Proxy>

ProxyPass /app/ balancer://mycluster/ 
ProxyPassReverse /app/ balancer://mycluster/

Upvotes: 0

emre
emre

Reputation: 677

Although I don't have much experience of using Apache HTTP server as a load balancer, looking at this page, I think you need to update your load balancer configuration as follows:

<Proxy balancer://mycluster>
    BalancerMember http://IPAddress1:8080/app/  route=tom
    BalancerMember http://IPAddress2:8080/app/  route=cat
    ProxySet lbmethod=byrequests stickysession=hazelcast.sessionId
</Proxy>

ProxyPass /app/ balancer://mycluster/ 
ProxyPassReverse /app/ balancer://mycluster/

Do we have a client where I could monitor hazelcast sessions?

You can use Hazelcast Management Center to monitor the cluster and browse the session entries that are stored in the Hazelcast IMap. All sessions are stored in a Hazelcast IMap keyed by their IDs. Please note that you need to enable Management Center on the members of your cluster before being able to see any data on Management Center.

You can also have a look into the Docker code samples for container based session replication to see a working configuration of session replication. Although there's none that uses Apache as a load balancer, there's one that uses Nginx which might be of help to you.

Upvotes: 1

Related Questions