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
- Generation of a terracotta configuration file
- Generation of terracotta enabled start up scripts for containers
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: Terracotta, Grails, Scalability, Java, Clustering
5 Comments currently posted.
Glen Smith says:
Steve says:
Really cool, I think Grails and Terracotta are going to be like peanut butter and jelly some day.
Robert says:
Does this plugin on do http session replication, or will it handle GORM stuff? such as 2nd level caching and maintaining cache state across the servers.
Jan says:
How did you manage that terracotta does not complain about nonshareable groovy classes like MetaClassRegistry, etc.? I tried to workaround this by instrumenting all groovy internal classes but I am told by terracotta that I should create locks for them. This is beyond what I am able to do… Thx
firehq says:
hi,thanks a lot for it.I use it.
and I have some questions.can it config grails-service in terracotta as see as single?my mean is if the grails-service has some state.
HelloService{
def List states=new ArrayList();
def put(String inState){
states.put(inState);
}
def get(){
return states;
}
}
this service is singleton scope.so,if I call this service on two tomcat,how the field “states” can be same?need config the tc-config.xml?or do other things?how?I need help.
Thank you all:)


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.