Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Open source Java projects: Terracotta

A unique approach to clustering conquers scalability and fail-over

  • Print
  • Feedback

Page 4 of 4

Both Tomcat instances showing the same data

Figure 4. Both Tomcat instances showing the same data

To see the data being clustered, click on the Monitor tab of the Sessions Configurator and log in using the default values: localhost on port 9520.

Figure 5 shows the Terracotta Server Monitor that I have navigated to the name attribute's value in the HttpSession.

Terracotta server monitor

Figure 5. Terracotta server monitor

Depending on your needs, you can modify the rules that Terracotta uses to determine what to cluster. In Figure 6, I've replaced the rule of clustering *..* with javax.servlet.http.HttpSession, so that Terracotta will cluster only the HttpSession object.

Configuring the clustering rules

Figure 6. Configuring the clustering rules

Once you are satisfied that your clustering is working, choose File -> Export Configuration. This generates a configuration file that you'll need to configure Tomcat with on startup to tell Terracotta which classes should be clustered.

Production deployment

To integrate Terracotta with Tomcat:

  1. Start the Terracotta Server by launching start-tc.server.bat or start-tc-server.sh from the Terracotta bin folder.
  2. Update the catalina.bat or catalina.sh script in the Tomcat bin folder to load Terracotta and point it to your configuration file:

    Unix/Linux:
    TC_INSTALL_DIR=<path_to_local_Terracotta_home>
    TC_CONFIG_PATH=<path_to_local_tc-config.xml>
    . $TC_INSTALL_DIR/bin/dso-env.sh -q
    export JAVA_OPTS="$TC_JAVA_OPTS $JAVA_OPTS"
    


    Windows:
    set TC_INSTALL_DIR=<path_to_local_terracotta_home>
    set TC_CONFIG_PATH=<path_to_local_tc-config.xml>
    %TC_INSTALL_DIR%\bin\dso-env.bat -q
    set JAVA_OPTS=%TC_JAVA_OPTS%;%JAVA_OPTS%
    
  3. Start the Tomcat servers using the startup.bat or startup.sh script.
  4. Hit your application on both servers and observe that the session is clustered.
  5. (Optionally) open the monitoring tab in the Sessions Configurator and find your clustered object value.

In conclusion

Terracotta's strategy is to bypass Java serialization, identifying only the components that change in stateful objects and then persisting those changes to the Terracotta server. Then when stateful objects are requested, the Terracotta client obtains the objects from the Terracotta server and injects them into the application. Bypassing Java serialization and hosting all data in a central server rather than sending data to all replicated servers aids in obtaining linear scalability. Configuring all application servers to connect to the Terracotta server and then injecting data as it is requested ensures reliability. Linear scalability and 100% reliability, all freely available as open source code -- who could ask for more?

Session clustering is but one of Terracotta's capabilities. You can use the technology to accomplish many things, including caching. For example, if you're building a new application and want to share data among multiple servers -- such as by using a distributed cache -- then Terracotta is an excellent solution: you can configure Terracotta to cluster a hashmap across all of your servers and store shared data in that hashmap.

About the author

Steven Haines is the founder and CEO of GeekCap, Inc., which provides technical e-learning courses for software developers. Previously he was the Java EE Domain Expert at Quest Software, defining software used to monitor the performance of various Java EE application servers. He is the author of Pro Java EE 5 Performance Management and Optimization, Java 2 Primer Plus, and Java 2 From Scratch. He is the Java host on InformIT.com and a Java Community Editor on InfoQ.com. Steven has taught Java at the University of California, Irvine and Learning Tree University.

Read more about Enterprise Java in JavaWorld's Enterprise Java section.

  • Print
  • Feedback

Resources

More from JavaWorld