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

About

whacko

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today