Session affinity/Sticky Session
Session affinity overrides the load-balancing algorithm by directing all requests in a session to a specific tomcat server. So when we setup the session affinity our problem will solved. But how to setup because session values are random value. We need to generate the session value some how identify the which tomcat generate response.
Step 1:
Tomcat configuration file (conf/server.xml) contain <Engine> tag have jvmRoute property for this purpose. So edit the config file and update the <Engine > tag like this
<Engine name="Catalina" defaultHost="localhost“ jvmRoute=“tomcat1” >
Here tomcat1 is worker name of this tomcat. check the workers.properties file in last post.
Change this line to all tomcat instances conf/server.xml file and change the jvmRoute value according to workers name and restart the tomcat instances.
Now all tomcat generate the session-id pattern like this
<Random Value like before>.<jvmRoute value>
ex: tomcat1 generate the session id like
Cookie:JSESSIONID=40025608F7B50E42DFA2785329079227.tomcat1
Cookie:JSESSIONID=40025608F7B50E42DFA2785329079227.tomcat1
So after update all tomcat instances conf/server.xml file to add the jvmRoute property to appropriate worker name values and restart the instances. All problem is fixed and entire load balance works fine even session based application.
Related Blogs:
Comments
Post a Comment