Monday Apr 30, 2007

Ruby on Rails meets GlassFish High Availability

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
  • 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 !


Friday Mar 16, 2007

JRuby and Rails - status

JRuby 0.9.8 is out and so is rails-integration 1.0. Rails 1.2.x has been out for a couple of months and there's a new release of ActiveRecord-JDBC 0.2.3. The good news is that JRuby 0.9.8 is lot more Rails compatible than ever before.

For GlassFish users this means:

  • For RoR deployed as a WAR - only the shared mode works. Therefore, instead of running that standalone rake task you should run 'rake war:shared:create'. You need to have the JRUBY_HOME enviroment variable set and a jruby/rails installation.
  • For RoR deployed directly on Grizzly, things seem to have regressed. Hopefully, we'll get the fixes real soon but there are workarounds and if you're interested email me at ashish dot sahni at sun dot com
Stay tuned ...

Tuesday Jan 02, 2007

Break report:

Before you know it the year end holiday break is over and it's back to the regular routine. Looking back at it I can't seem to remember doing much :) But time sure did fly. So what did I do ?

Well, there was the trip to the INS, the lying on the couch to watch the entire season 6 (part 1) of 'The Sopranos', attending the yoga classes and swimming at the gym, getting together with friends on Christmas and New Year's Eve weekends, reading a (little) bit and of course playing squash. Given that the I was out pretty much the most of the last quarter CY '07 due to plantar fasciitis, I'm extremely glad to be back on the court. And, I did give myself the Christmas gift of a new squash racquet - Head Liquid Metal 140. This racquet is much better than the other Prince racquets I'd been playing with so far. Hopefully it won't break too soon. Let me take this opportunity to invite my Sun brethren who play squash for a game when they are in the San Francisco Bay area.

Also, there were a few todo items on my list for the break, but they did not get done :( Maybe in the next few days, weeks ... Happy 2007 !

Monday Aug 14, 2006

Howto add unit tests in Glassfish

A primer on howto add unit tests in Glassfish[Read More]



« February 2016