One of the key features of
GlassFish v2 release is its cluster support. Various
GlassFish server instances can be grouped together to form a single virtual entity - a cluster. One of the salient services offered via clustering is high availability, which
is implemented as in-memory replication of state across participating server instances.
Since, I've been looking at getting Ruby on Rails applications running as web applications in a Java EE container, I was asked a couple of weeks ago if RoR applications could run in a
GlassFish cluster.
Well, with Rails-Integration 1.1.1, you can ! Its relatively straightforward to enable failover support for a web application in
GlassFish and is no different for RoR (as a web application).
The hard part, or so it seems at first, is setting up the
GlassFish cluster.
For the easy part first, the only changes needed to enable failover session support for a web application
are :
-
The deployment descriptor, web.xml, needs a marking distributable element - <distributable/>
-
Enable the high availability flag during deployment. For command line, this would be of the form
${GLASSFISH_HOME}/bin/asadmin deploy --target ${CLUSTER_NAME} --availabilityenabled=true ${path-to-war-file}
One important fact that I learned during this process, was that a load balancer facade is not necessarily needed for development/testing scenario. In other words if server instances, that share application state, are listening on the same host (different port), then failover can be simulated by simply sending requests to the other node (port).
Now, the part about setting up a
GlassFish cluster. The references below give detailed information about the clustering architecture and setup steps but the takeaway is a lot simpler.
-
Download GlassFish v2 from https://glassfish.dev.java.net/public/downloadsindex.html
-
java -Xmx256m -jar ${GLASSFISH-v2.jar downloaded above}
-
cd glassfish;
ant -f setup-cluster.xml
-
{GLASSFISH_HOME}/bin/asadmin start-domain ${domain-name} // ${domain-name} typically is 'domain1'
-
cd ${GLASSFISH_HOME}/samples/quickstart/clusterjsp/
-
${GLASSFISH_HOME}/bin/asant setup-one-machine-cluster
-
${GLASSFISH_HOME}/bin/asant start_cluster // stop_cluster to stop
(The last 2 steps will create a cluster named 'cluster1' with two instances, instance-ONE and instance-TWO listening for HTTP requests on port 1110 and 1111 respectively. Of course, you could
do the same(creating/starting/stopping) via the asadmin command options like '(create|start|stop)-(cluster|instance|node-agent)', but
it's a lot easier to get started via the clusterjsp sample)
That's all there is to it !
References
http://wiki.glassfish.java.net/gfwiki/Wiki.jsp?page=GlassFishV2Architecture
http://developers.sun.com/appserver/reference/techart/load-balancing.html
https://glassfish.dev.java.net/javaee5/build/GlassFish_LB_Cluster.html
http://wiki.glassfish.java.net/gfwiki/attach/OnePagersOrFunctionalSpecs/memory-replication-one-pager.html
rails-integration 1.1.1 has just been released !
Source and binaries can be downloaded from
http://rubyforge.org/frs/?group_id=2014
rails-integration details can be found at
http://www.headius.com/jrubywiki/index.php/Rails_Integration
The fundamental change in this release as compared to 1.0, is performance and compatibility.
When used in standalone mode, rails-integration 1.0 had this hack wherein it performed
installation of
JRuby and the rails libraries at runtime (during web application
initialization i.e., once per web container process lifetime). Not only was this ugly, but
it also caused compatibility problems with
GlassFish since it expected the web application constituents after deployment (implementation dependent)in a particular format. No runtime installation needed with 1.1.1 !
Aiding to the performance improvements is
JRuby 0.9.9
which has made great strides in improving performance as compared to its previous versions.
Also, this release is compatible with rails 1.2.x, solves session related and other issues that plagued 1.0.
All in all, a great release that blends the two architectures - RoR and Java EE - giving you the best of both worlds - the development convenience of RoR and the enterprise level features of the Java EE platform. No longer do you have to pick and choose one !
Many thanks to all the folks involved in getting the release out !