Tomcat cluster session replication problem
1. Only a hint. Do you have the following lines in your configuration files.
2. Update to 3.6.3 look here .
File: web.xml
<!-- 'distributable' Make the application suitable for running in an distributed environment like a tomcat clustering --> <distributable /
File: zk.xml
<!-- start SESSION REPLICATION function --> <!-- needed for running a zk application in a CLUSTER --> <system-config> <ui-factory-class> org.zkoss.zk.ui.http.SerializableUiFactory </ui-factory-class> </system-config>
best
Stephan
Yes, I have these lines in my configuration files.
The cluster configuration seems to work fine, all my session attributes are replicated properly except for the "javax.zkoss.zk.ui.Session" object, the zk session. This object does not replicates its internals.
On the active node, the "javax.zkoss.zk.ui.Session" contains all the same attributes as the native session. But on the replicated node, the "javax.zkoss.zk.ui.Session" is created but contains no attributes... BUT, if I start only the first tomcat node, login, then start the second node, the internal attributes of this particular session are there after the initial session transfer! But as I navigate through the application, the attributes are not synced any more.
It looks like the tomcat delta manager does not see the internal object modifications so it never replicates the zk session object again after the initial transfer.
I will give a try with 3.6.3, thanks for the suggestion.
Thanks a lot,
Sylvain
Hi Silvain,
The package have changed to org.zkoss.zk.ui.http;
public class SerializableUiFactory extends AbstractUiFactory {
public Session newSession(WebApp wapp, Object nativeSess, Object request) {
return new SerializableSession(wapp, (HttpSession)nativeSess, request);
}
Do you really have the code in it?
<system-config> <ui-factory-class> org.zkoss.zk.ui.http.SerializableUiFactory </ui-factory-class> </system-config>
Do you have ever heared from the Teracotta clustering framework ?
best
Stephan
Hi Stephan,
I verified again and yes, I have the org.zkoss.zk.ui.http.SerializableUiFactory in my zk.xml.
Here is the content of my zk.xml:
<!DOCTYPE zk PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- zk.xml
Purpose:
Description:
History:
Created by ZK Studio
-->
<zk>
<system-config>
<ui-factory-class>
org.zkoss.zk.ui.http.SerializableUiFactory
</ui-factory-class>
<cache-provider-class>
org.zkoss.zk.ui.impl.GlobalDesktopCacheProvider
</cache-provider-class>
<disable-event-thread />
</system-config>
<device-config>
<device-type>ajax</device-type>
<timeout-uri>/timeout.zul</timeout-uri>
</device-config>
<desktop-config>
<desktop-timeout>-1</desktop-timeout>
</desktop-config>
<session-config>
<session-timeout>1200</session-timeout> <!-- zk session timeout. -->
<timer-keep-alive>true</timer-keep-alive>
</session-config>
<listener>
<description>Listener for zk session init</description>
<display-name>Session manager</display-name>
<listener-class>com.ui.desktop.session.SessionManager</listener-class>
</listener>
</zk>I will take a look at Teracotta, I already heard this name but never investigated further on this product.
Thanks,
Sylvain
Does anyone build a TIM (Terracotta integration module) for ZK ?
If not, Terracotta responsibles, including the CTO, are open to work hand in hand for making the integration happens.
That's an invitation to the ZK responsibles project :)
Hi ~
tomcat need to config setting for cluster, you could refer to
https://sec1.woopra.com/docs/cluster-howto.html
Hey everyone, we are currently in the process of establishing a relationship with the Terracotta team. I will keep you up to date on future events.
I've tried Terracotta and it works really well, but I have not been able to make it work with zk.
This is really good to know, I'll follow this with great interest, thanks! :-)
Sylvain
Great news tmillsclare !
If for any reasons, that relationship or whatever does not work as desired, there are also complete free alternatives :
- Hazelcast http://www.hazelcast.com/product.jsp
- Shoal https://shoal.dev.java.net/
It sounds very promising with a Terracotta integration module for ZK. Any more news on that?
@fredrikoe2, please refer to
http://docs.zkoss.org/wiki/How_To_Run_ZK_With_Terracotta
Hi Peter.
I have tried your example but I don't get it to work. I don't use Tomcat but Jetty through the Terracotta Sessions Configurator. I've made a simple JSP similar to your ZUL to make sure the session replication works. However, when I try to run your ZUL, I get:
"
*******************************************************************************
Attempt to share an instance of a non-portable class by passing it as an argument to a method of a
logically-managed class. This unshareable class has not been included for sharing in the
configuration.
For more information on this issue, please visit our Troubleshooting Guide at:
http://terracotta.org/kit/troubleshooting
Thread : 6720997@qtp-25125157-4
JVM ID : VM(1)
Logically-managed class name: java.util.HashMap
Logical method name : put(Object,Object)
Non-included classes : org.zkoss.zk.ui.http.SerializableSession, org.zkoss.zk.ui.http.SimpleSession
Under most circumstances, you should only be adding classes for your
application. If you are adding classes for frameworks or code not written by
you, then you should consider finding a Terracotta Integration Module (TIM)
that matches the framework you are using.
As an example, if the non-portable class listed below is
net.sf.ehcache.CacheManager, you should consider using the ehcache TIM.
It is also possible that some or all of the classes above are truly
non-portable, the solution is then to mark the referring field as transient.
For more information on non-portable classes see the Troubleshooting Guide.
Action to take:
1) Reconfigure to include the unshareable classes
* edit your tc-config.xml file
* locate the <dso> element
* add this snippet inside the <dso> element
<instrumented-classes>
<include>
<class-expression>org.zkoss.zk.ui.http.SerializableSession</class-expression>
</include>
<include>
<class-expression>org.zkoss.zk.ui.http.SimpleSession</class-expression>
</include>
</instrumented-classes>
* if there is already an <instrumented-classes> element present, simply add
the new includes inside it
*******************************************************************************
Caused by:
com.tc.exception.TCNonPortableObjectError: ..."
This made me believe that an integration module for ZK is needed. Or do you have any other suggestions?
@fredrikoe2
Can you follow the smalltalk and run the sample on tomcat first?
I've tried your example in Tomcat now and get it to work. However, in my application I also need to cluster other stuff that is running in the app server, not only the session. Therefore I need a "custom installation" described here: http://www.terracotta.org/documentation/ga/product-documentation-18.html#379876512_pgfId-1006124 (you need to register at terracotta.org and loging to view this page). That is a different way of integrating Tomcat and Terracotta without TerracottaTomcat60xSessionValve. When I do this I get the same errors from Terracotta as above.
@fredrikoe2,
we haven't scheduled to provide our own TIM of ZK.
We are evaluating the effort it cost and how strong is the market need.
Anyone feels the need of TIM, please contact info at zkoss dot org.
All who intrested in integration ZK with Terracotta please vote for this issue on JIRA by this link http://jira.terracotta.org/jira/browse/CDV-1492
It's nessesary to fill the register form on Terracotta site by this link http://terracotta.org/account/register for voting.
PeterKuo I think that market offer create the market need. Terracotta is powerfull and industrial solution for clustering. Is any real alternative for clustering ZK applications? That is why market need will be in future? There are ready TIMs for such java frameworks as iBATIS, Spring, Guice, Rife, Wicket.
ZK - Open Source Ajax Java Framework
Hello,
I'm having a problem with zk session replication in a tomcat clustered environment.
ZK: 3.6.2
Tomcat: 6.0.20
I'm fairly new in the zk/webapps world so I may be missing something very basic...
My problem is that the internals/attributes of the "javax.zkoss.zk.ui.Session" session attribute (ZK SerializableSession inside the HttpSession) are not replicated.
My feeling is that the ZK session is created, replicated, then populated, but the tomcat DeltaManager doesn't seem to detect the internal changes after the initial replication thus it doesn't re-replicate the object. As a result, when I shutdown my first tomcat instance, the session is not able to failover properly on the second instance because of the missing attributes and I have to login again.
However, if I start only 1 tomcat instance, login, then start the second instance, all the attributes of the javax.zkoss.zk.ui.Session are there and I am able to make one failover switch. But it works only one time for the currently logged users and any other modification to the zk session seem to be ignored by the delta manager.
I tried a few workarounds:
- Implemented a SessionListener and tried to do a setAttribute("....", getAttribute("....")) of the javax.zkoss.zk.ui.Session session object. Didn't worked, still get no attributes in my zk session on node 2.
- Tried to set a new session attribute "saved_session" and put the zk session object in it. On node 1 the session attributes are there correctly, on node 2, no attributes in the object.
- getAttribute of the zk session in the "saved_session" object, deleteAttribute of the zk session object (javax.zkoss.zk.ui.Session) and recreate with the "saved_session" object. Again, on node 1 all the session attributes are there, on node 2, no attributes in the object (but the object exists, its not null).
- I then implemented a servlet filter and tried all the same tricks as in the session listener but still no luck, it doesn't work. Session object is created properly on node 2 (not null) but still no attributes in it.
What is really frustrating is that if I set attributes of other type than javax.zkoss.zk.ui.Session, the replication works well, things are replicated properly.
So, if anybody has any tip/trick/hint to help me, I'll really appreciate! My next idea would be to modify the tomcat DeltaManager code but there must be another way, I have difficulty to believe that I have to go this deep to make this work properly.
Thanks a lot,
Sylvain