Nov 16, 2009

Clustering in JBoss Application Server

Introduction

Whenever business wants to run their IT applications in a scalable and reliable way, they need to have a highly sophisticated environment, which suits their needs. The motto is to keep the business up and running, all the time 24 x7, without any breaks and troubles. Performance also cannot be compromised in this fast growing world. For any J2EE application built and deployed in most widely used, open source application Server like JBoss, Clustering comes in handy to take care of the scalability, reliability and the application availability with no compromise on performance as well. This paper will describe about the clustering concepts in JBoss Application Server

Clustering

Clustering allows us to run an application on several parallel servers (i.e. cluster nodes) while providing a single view to application clients. Load is distributed across different servers, and even if one or more of the servers fails, the application is still accessible via the surviving cluster nodes. It is crucial for scalable enterprise applications, as you can improve performance by simply adding more nodes to the cluster.

The JBoss Application Server (AS) comes with clustering support out of the box. The simplest way to start a JBoss server cluster is to start several JBoss instances on the same local network, using the run -c all command for each instance. Those server instances, all started in the all configuration, detect each other and automatically form a cluster.

What is a Cluster?

A cluster is a set of nodes. In a JBoss cluster, a node is a JBoss server instance. Thus, to build a cluster, several JBoss instances have to be grouped together (known as a "partition"). On a same network, we may have different clusters. In order to differentiate them, each cluster must have an individual name.

clip_image001

Following figure shows an example network of JBoss server instances divided into three clusters, with each cluster only having one node. Nodes can be added to or removed from clusters at any time.

Each JBoss server instance (node) specifies which cluster (i.e., partition) it joins in the ClusterPartition MBean in the deploy/cluster-service.xml file. All nodes that have the same ClusterPartition MBean configuration join the same cluster. Hence, if you want to divide JBoss nodes in a network into two clusters, you can just come up with two different ClusterPartition MBean configurations, and each node would have one of the two configurations depending on which cluster it needs to join. If the designated cluster does not exist when the node is started, the cluster would be created. Likewise, a cluster is removed when all its nodes are removed.

The following example shows the MBean definition packaged with the standard JBoss AS distribution. So, if you simply start JBoss servers with their default clustering settings on a local network, you would get a default cluster named DefaultPartition that includes all server instances as its nodes.

<mbean code="org.jboss.ha.framework.server.ClusterPartition" name="jboss:service=DefaultPartition">      
<! -- Name of the partition being built -->
<attribute name="PartitionName">
${jboss.partition.name:DefaultPartition}
</attribute>
<! -- The address used to determine the node name -->
<attribute name="NodeAddress">${jboss.bind.address}</attribute>
<! -- Determine if deadlock detection is enabled -->
<attribute name="DeadlockDetection">False</attribute>
<! -- Max time (in ms) to wait for state transfer to complete.
Increase for large states -->
<attribute name="StateTransferTimeout">30000</attribute>
<! -- The JGroups protocol configuration -->
<attribute name="PartitionConfig">
... ... </attribute>
</mbean>


Setting up the clustering



Following procedure lets us know how to set up the clustering in JBoss Application Server.



Using Clustered EJBs



Since nodes in a JBoss cluster automatically discover the existence of one another, it is very easy to set up your EJBs to be cluster-enabled. Simply setting a clustering flag in the JBoss-specific bean deployment descriptor, jboss.xml, is enough to enable load-balancing, fail-over, and state replication for your beans.



Example 1. jboss.xml



<?xml version="1.0" encoding="UTF-8"?>
<jboss>
<enterprise-beans>
<session>
<ejb-name>MyEJB</ejb-name>
<jndi-name>MyEJB</jndi-name>
<clustered>true</clustered>
</session>
<entity>
<ejb-name>MyEntity</ejb-name>
<jndi-name>MyEntity</jndi-name>
<clustered>true</clustered>
</entity>
</jboss>


Using Cluster-wide JNDI


Remote clients can connect to and use the cluster-wide JNDI tree simply by leaving the provider URL undefined. JBoss will use IP multicast to discover clustered JNDI.



Example 2. jndi.properties



java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces


Using Farming



Farming is not enabled by default, so you'll have to set it up yourself. Simply create the XML file shown below and copy it to the JBoss deploy directory $JBOSS_HOME/server/all/deploy.



Example 3. farm-service.xml



<?xml version="1.0" encoding="UTF-8"?>
<server>
<classpath codebase="lib" archives="jbossha.jar"/>
<!--these depends tags no longer do anything
<depends>jboss:service=Naming</depends>
<depends>jboss.system:service=ServiceDeployer</depends>
<depends>jboss:service=DefaultPartition</depends>
-->
<mbean code="org.jboss.ha.framework.server.FarmMemberService"
name="jboss:service=FarmMember,partition=DefaultPartition" >
<attribute name="PartitionName">DefaultPartition</attribute>
<attribute name="FarmDeployDirectory">./farm</attribute>
<attribute name="ScannerName">jboss.deployment:type=DeploymentScanner,flavor=URL</attribute>
</mbean>
</server>


After deploying farm-service.xml, you are ready to rumble. With the above configuration, just copy your farmed components into the $JBOSS_HOME/server/all/farm directory, and they will be hot-deployed across the cluster.



Starting JBoss



JBoss comes with three different ready-to-use server configurations: minimal, default, and all. Clustering is only enabled in the all configuration. To run this configuration, you must execute JBoss as follows:



run.bat -c all



JBoss Features



The following is a clustering feature overview for JBoss Servers:




  • Automatic cluster membership discovery.


  • Fail-over and load-balancing features for JNDI, RMI, Entity Beans, Stateful Session Beans with in-memory state replication, and Stateless Session Beans.


  • Pluggable load-balance policies.


  • HTTP session replication with Tomcat and Jetty (CVS HEAD only).


  • Dynamic JNDI discovery. JNDI clients can automatically discover the JNDI InitialContext.


  • Cluster-wide replicated JNDI tree.


  • Network Boot.


  • Farming: Distributed cluster-wide hot-deployment



Conclusion



JBoss clustering is designed to be simple to configure and simple to extend. It is one of the final pieces of the puzzle that makes JBoss a viable open source competitor to other enterprise J2EE offerings.



References




1 comments:

Pardhasaradhi said...

Good stuff mentioned here.... All the details including the configuration that are to be made in JBoss are mentioned...

Text Widget

Copyright © Vinay's Blog | Powered by Blogger

Design by | Blogger Theme by