How To Run ZK With Terracotta

From Documentation
Revision as of 05:03, 22 March 2013 by Samchuang (talk | contribs) (→‎Setup Steps)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
DocumentationSmall Talks2010MarchHow To Run ZK With Terracotta
How To Run ZK With Terracotta

Author
Peter Kuo, Engineer, Potix Corporation
Date
March 31, 2010
Version
ZK 5

Introduction

By leveraging services offered by Terracotta, a clustering software for Java, ZK applications have an additional way[1] 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.


  1. 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).

Test Environment

  1. Tomcat 6
  2. ZK Demo with ZK 5
  3. Terracotta 3.2.1 beta
  4. Windows 2003R2
  5. JDK 1.6

Demo

A ZK demo application running on two Tomcats, sharing session data through Terracotta.

Setup Steps

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.

set JAVA_OPTS="-XX:PermSize=512M"

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.

Summary

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.

Use Case

If you have a use case to share with us running ZK on Terracotta, please contact us at info@zkoss.org

See Also

  1. ZK Clustering -- from ZK forum
  2. How to Run ZK on Apache + Tomcat clustering, Part I
  3. How to Run ZK on Apache + Tomcat clustering, Part II
  4. Clustering Web Applications with Terracotta -- from Terracotta official site
  5. Web Sessions Express Installation -- from Terracotta official site

Comments



Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.