I'm trying to enable session replication in liferay on tomcat without much luck. I have written a small test to see if sessions are being replicated and it works well in a separate JSP file that I have placed under webapps/examples but when I input the same code in a liferay-porlet only the JSESSION are correct.
HttpSession httpSession = request.getSession();
String testTime = (String) httpSession.getAttribute("testTime");
String before = testTime;
testTime = Long.toString(System.currentTimeMillis());
httpSession.setAttribute("testTime", testTime);
String sessionid = httpSession.getId();
System.out.println("JSESSIONID: "+sessionid);
System.out.println("TEST TIME WAS: "+before);
System.out.println("TEST TIME IS: "+testTime);
Anybody got an idea of why its not working in the liferay-portlet? I have added distributable to portlet/WEB-INF/web.xml
Edit 1: Versions
liferay 6.1.1
Tomcat 7.0.47
Edit 2: I tried another test.
HttpSession httpSession = request.getSession();
String testTime = (String) httpSession.getAttribute("testTime");
String before = testTime;
if(testTime == null) {
testTime = Long.toString(System.currentTimeMillis());
httpSession.setAttribute("testTime", testTime);
}
String sessionid = httpSession.getId();
System.out.println("JSESSIONID: "+sessionid);
System.out.println("TEST TIME WAS: "+before);
System.out.println("TEST TIME IS: "+testTime);
this time i only set the variable if its null. And it works as expected in the JSP outside of liferay but within liferay it goes like this.
It does not matter which server gets the first request its always the same outcome anyway
Edit 4. Cluster info
Nodes: 2 Load-balancer:
<Proxy balancer://mycluster>
BalancerMember ajp://node1:8009 route=tomcat1 loadfactor=1
BalancerMember ajp://node2:8009 route=tomcat2 loadfactor=1
Order Deny,Allow
Deny from none
Allow from all
ProxySet lbmethod=byrequests
</Proxy>
<Location /balancer-manager>
SetHandler balancer-manager
Order deny,allow
Allow from all
</Location>
ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/
portal-ext.properties
cluster.link.enabled=true
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://dbserver:3306/lportal?autoReconnect&autoReconnectForPools;&useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=u jdbc.default.password=p
spring.configs=\
META-INF/base-spring.xml,\
\
META-INF/hibernate-spring.xml,\
META-INF/infrastructure-spring.xml,\
META-INF/management-spring.xml,\
\
META-INF/util-spring.xml,\
\
META-INF/jpa-spring.xml,\
\
META-INF/executor-spring.xml,\
\
META-INF/audit-spring.xml,\
META-INF/cluster-spring.xml,\
META-INF/editor-spring.xml,\
META-INF/jcr-spring.xml,\
META-INF/ldap-spring.xml,\
META-INF/messaging-core-spring.xml,\
META-INF/messaging-misc-spring.xml,\
META-INF/mobile-device-spring.xml,\
META-INF/notifications-spring.xml,\
META-INF/poller-spring.xml,\
META-INF/rules-spring.xml,\
META-INF/scheduler-spring.xml,\
META-INF/scripting-spring.xml,\
META-INF/search-spring.xml,\
META-INF/workflow-spring.xml,\
\
META-INF/counter-spring.xml,\
META-INF/mail-spring.xml,\
META-INF/portal-spring.xml,\
META-INF/portlet-container-spring.xml,\
META-INF/staging-spring.xml,\
META-INF/virtual-layouts-spring.xml,\
\
META-INF/dynamic-data-source-spring.xml,\
#META-INF/shard-data-source-spring.xml,\
#META-INF/memcached-spring.xml,\
#META-INF/monitoring-spring.xml,\
\
META-INF/ext-spring.xml
If you want proper session replication, you should declare the portal as well as all plugins as distributable
. The reason is that each one is a separate webapp.
However, utilizing session replication generates a huge amount of overhead. If you build a cluster for performance reasons, you're eating quite a bit of the added performance right away.
The standard advice (I know, you're not asking for this, but I'd like to see it in here for others finding the question later) is to rely on sticky sessions. If you ever want to shut down one appserver, take it out of the load balancer, but keep it online to serve the already allocated sessions for a while (they'll run out eventually). Not using session replication will typically lower the required processing capacity dramatically. Yes, there are some applications that definitely need session replication, but I'd estimate them to be 10% of those that initially want to use this feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With