ALTERthought Blogs

2 September 2008

Terracotta Plugin for Grails

I have created a new Grails Plugin to help in the development of Grails applications clustered using Terracotta. The details of this plugin can also be found at http://www.grails.org/Terracotta+Plugin.
Terracotta is a Java infrastructure that allows you to scale your application by clustering JVMs.

Features

Installation
grails install-plugin terracotta

Usage
Install the plugin
Run the start up script generation task
Run the terracotta configuration generation task
generate a war for the application and deploy in a container
start the terracotta server(s)
start the application servers

Components
Generate<ContainerName>Script: Generate the start up script for an application server
GenerateTcConfig: Generate the tc-config.xml file for terracotta

Generate<ContainerName>Script
Currently only 2 containers are supported: jboss and tomcat.

Edit TerracottaConfig.properties to set the parameters for the start up scripts:
The terracotta install directory on the target jboss or tomcat server:
terracotta.install.dir
The path place where the tc.config.xml will be made available to on the servers (this plugin does not remote copy it you have to do that):
terracotta.config.path

Run:
grails generate-jboss-scripts

Copy the generated scripts in the startup script folders of the containers. You will later start the containers using these scripts instead of standard ones.

GenerateTcConfig
Generates the tc-config.xml required to run a terracotta enabled container.
It enables the clustering of all the domain classes defined in the project and allows to add any additional classes to be made clusterable by including a user defined xml segment.
It also clusters the http sessions across the container instances for your application.

Edit TerracottaConfig.properties to set the host names and ports for the terracotta servers to be used by the application.

Edit CustomIncludes.xml to specify any additional terracotta include rules required by your application.

Run:
grails generate-tc-config

Copy the generated file on each container server, in the location specified when generating the container start up scripts.

Running the Clustered Application
Deploy your application on all the container instances.
Start the terracotta server(s)
Start the containers using the generated start up scripts. (Note that you will need a form of load balancing to witness the effects of the clustering, I used Apache with mod_jk)

Fun Note
Start one only one node of your cluster. Start a session (log in your app, …). Stop that server instance, then start another one. Continue using your application without losing your session!

Looking Ahead
Future enhancements include support for more containers (easy), and support for running terracotta in development mode (more complex).

Technorati Tags: , , , ,

    del.icio.us

2 Comments currently posted.

Glen Smith says:

Awesome work! I have the terracotta book sitting on my bookshelf and was thinking that getting up and running was going to take a bit of exploration…. now it’s all done! Can’t wait to try this out.

Steve says:

Really cool, I think Grails and Terracotta are going to be like peanut butter and jelly some day.

Post a comment on this entry: