By leveraging services offered by Terracotta, a clustering software for Java, ZK applications have an additional way to be scaled to large virtualized environments and clouds. As a proof of concept, we'll run a ZK demo application on two Tomcats connected to a single Terracotta server on the same machine and demonstrate how to run ZK with Terracotta.
- ↑ ZK is clustering ready for any Web server supporting clustering, including but not limited to, Tomcat, Google App Engine, and Amazon EC2.
More on Terracotta
Terracotta is an open source JVM-level clustering software for Java. It delivers clustering as a run-time infrastructure service, which simplifies the task of clustering a Java application immensely, by effectively clustering the JVM underneath the application, instead of clustering the application itself. Terracotta for Web Sessions allows users to access session data coherently and reliably on the Terracotta server(s).
- Tomcat 6
- ZK Demo with ZK 5
- Terracotta 3.2.1 beta
- Windows 2003R2
- JDK 1.6
A ZK demo application running on two Tomcats, sharing session data through Terracotta.
Follow the document from Terracotta official site Web Sessions Express Installation
Add the following snippet to context.xml in Tomcat 6.
<Valve className="org.terracotta.session.TerracottaTomcat60xSessionValve" tcConfigUrl="localhost:9510"/>
Add the following declaration to catalina.bat in Tomcat 6 to prevent out of memory error.
Add the following code to zk.xml to enable session serialization.
<system-config> <disable-event-thread/> <ui-factory-class>org.zkoss.zk.ui.http.SerializableUiFactory</ui-factory-class> </system-config> <listener> <listener-class>org.zkoss.zkplus.cluster.ClusterSessionPatch</listener-class> </listener>
Write a test zul to see if session data is shared by two Tomcats.
<window title="Share same session in two tomcat" border="normal" width="300px"> <button label="set time in session" onClick='session.setAttribute("insession",(new Date()).toString());state.value="already set time"' /> <button label="get time in session" onClick='result.value=session.getAttribute("insession")' /> <vbox> <label id="state" value=""/> <label id="result" value=""/> </vbox> </window>
start Terracotta server.
start application server.
Through this simple environment setup and testing, we've demonstrated that ZK application running on multiple servers can share session data through the Terracotta server reliably and efficiently. This article serves as a proof of concept for how ZK can be integrated to run with Terracotta and leverage its scalability.
If you have a use case to share with us running ZK on Terracotta, please contact us at firstname.lastname@example.org
- ZK Clustering -- from ZK forum
- How to Run ZK on Apache + Tomcat clustering, Part I
- How to Run ZK on Apache + Tomcat clustering, Part II
- Clustering Web Applications with Terracotta -- from Terracotta official site
- Web Sessions Express Installation -- from Terracotta official site
|Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.|