Welcome!

Java Authors: Sematext Blog , Elizabeth White, Noel Wurst, Liz McMillan, Yeshim Deniz

Related Topics: Java, Cloud Expo, Apache

Java: Article

Dynamic Clustering for J2EE Cloud Environments

Cloud computing is one of the emerging paradigms in today's computing world

Cloud computing is one of the emerging paradigms in today's computing world. One of the main advantages of migrating to the cloud is its elastic nature. Elasticity allows dynamic provisioning and de-provisioning of resources according to the application's workload requirement.

In a traditional on-premise J2EE infrastructure, information about the application server and web server resources are available during deployment. Clustering of such an infrastructure to achieve scalability is much simpler since the information about resources is known beforehand. But in a cloud environment, because of its elastic nature, resources get provisioned and de-provisioned dynamically based on the workload. So a j2ee cloud environment has challenges like reconfiguring automatically for the addition/removal of application server instances to/from the cluster. One solution from the open source space is to use Apache Httpd web server with mod_cluster load balancing module and JBoss application server.

The article will discuss the features of mod_cluster which enable it to operate in a cloud environment and also the steps to set up a highly scalable J2EE cloud environment in your lab.

Introduction to mod_cluster
mod_cluster is an extension of the Apache httpd mod_proxy load balancing module and can balance http requests across multiple instances of JBoss Application Server, JBoss Web standalone, or Tomcat. The unique feature of mod_cluster is that once the initial configuration is done, there is no need of any manual configuration changes for adding or removing JBoss AS or Tomcat instances.

mod_cluster uses two communication channels for its working. It uses ajp, http or https to forward requests from httpd to one of the application server nodes. The backward channel is used by the application server nodes to send server side information to the httpd side and is the key differentiator for mod_cluster with respect to other load balancing modules. This channel sends real time information about load balancing factors for each node and application life cycle events.

Some of the key features of mod_cluster that enable it to be used in cloud environments are

Dynamic configuration
Common httpd based load balancers like mod_jk and mod_proxy require the configuration of workers (application servers) at the httpd side. So if you want to add a new worker, you will have to change the configuration in httpd side and restart the proxy. This is an overhead in case of large or dynamically varying clusters like in cloud environments.

But with mod_cluster the proxy information is maintained in the application server side through a static list or through the advertise mechanism (using mod_advertise) . As the workers start, the listeners receive multicast pings which contain the host and port information about the proxies. Now the workers can send events to the detected proxies and the proxies auto configure themselves to balance request between the nodes.

Dynamic determination of load balancing factor
In common httpd based load balancers, the ratio in which load is distributed among the workers is determined by a static factor we provide at the httpd load balancer configuration. But in the case of mod_cluster the load balancing factor is determined at the application server side based on the real time values monitored at runtime. Load computation is pluggable and you can write your own LoadMetric based on the metric you want in addition to the default load metrics.

Fine grained web application life cycle
In the case of mod_cluster, the applications deployed in the application server side are registered with the httpd side through the Mod-Cluster Management protocol. So the http side has information about which all applications are deployed in which instances and transfers the requests only to the nodes which have the requested application. Since the proxies have information on the applications deployed on each of the workers, we can keep highly sensitive applications on our private cloud and move lesser critical applications to some public provider. This enables us to scale up without compromising security as the data sensitive applications will be in our local premises only . For example in a shopping cart scenario browsing the catalog can go into the public cloud and sensitive requirements like payments can stay in company's private cloud.

The following section describes how we can set up a highly scalable j2ee environment using vmware(or any other private cloud solution like Eucalyptus or Open Nebula) in your lab setup.

Environment Set-Up
We have VMware vCenter server setup in one of the machines and connected to an ESXi host. The discussion is based on the assumption that the reader knows how to create a virtual machine and install guest operating system in a vmware environment. Our virtual machine has CENTOS 5.4 installed in it.

To set up dynamic cluster in cloud, we need minimum of two instances:

  1. Apache httpd + mod_cluster
  2. JBoss 5.1 application server with mod_cluster

Now we can look into creating each of these images/templates with necessary startup scripts in details. These steps can be done in any of the CentOS 5 installed machine or virtual machines.

Creating Apache httpd image
Step 1. Create a base virtual machine with centos 5.x as the guest operating system.
Refer creating a virtual machine and installing guest os for VMWare virtual machine creation.

Step 2. Install Apache httpd and mod_cluster in the virtual machine
Download the apache httpd integrated with latest mod_cluster distribution here. To install httpd with mod_cluster, move the distribution to the vm and extract mod_cluster-1.1.xxx-linux2-x86-ssl.tar.gz file using the following command

tar xvf mod-cluster-1.1.0.xxx-linux2-x86-ssl.tar.gz

This by default installs httpd with required mod_cluster modules in /opt/jboss directory.

Step 3. Configuring mod_cluster at httpd side
The httpd configuration file will be httpd.conf which is located in /opt/JBoss/httpd/httpd/conf. From mod_cluster1.1.0CR2 mod_cluster comes with some quick start values.

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

LoadModule slotmem_module modules/mod_slotmem.so

LoadModule manager_module modules/mod_manager.so

LoadModule proxy_cluster_module modules/mod_proxy_cluster.so

LoadModule advertise_module modules/mod_advertise.so

The above configuration specifies the extra modules required for httpd with mod_cluster. If you are adding mod_cluster to the existing httpd installation, you have to download the modules and add the above configuration to httpd.conf file.

# MOD_CLUSTER_ADDS

# Adjust to you hostname and subnet.

<IfModule manager_module>

Listen *:6666

ManagerBalancerName mycluster

<VirtualHost *:6666>

<Directory />

Order deny,allow

Deny from none

Allow from all

</Directory>

KeepAliveTimeout 300

MaxKeepAliveRequests 0

#ServerAdvertise on http://@IP@:6666

AdvertiseFrequency 5

#AdvertiseSecurityKey secret

#AdvertiseGroup @ADVIP@:23364

<Location /mod_cluster_manager>

SetHandler mod_cluster-manager

Order deny,allow

Deny from none

Allow from all

</Location>

</VirtualHost>

</IfModule>

Customize the above configuration for your own needs as this is not suitable for production environment.

Step 4. Starting httpd at boot up
We need the httpd to be up and running when the machines boots up. To achieve this we have to expose httpd as a service through init scripts.

The below script can be used to start and stop httpd at boot up.

#!/bin/sh

# chkconfig: - 64 36

# description: Apache Start|Restart|Stop Web Server

APACHE_HOME=/opt/jboss/httpd

case "$1" in

start)

echo "Starting Apache ..."

# Change the location to your specific location

$APACHE_HOME/sbin/apachectl start

;;

stop)

echo "Stopping Apache ..."

# Change the location to your specific location

$APACHE_HOME/sbin/apachectl stop

;;

graceful)

echo "Restarting Apache gracefully..."

# Change the location to your specific location

$APACHE_HOME/sbin/apachectl graceful

;;

restart)

echo "Restarting Apache ..."

# Change the location to your specific location

$APACHE_HOME/sbin/apachectl restart

;;

*)

echo "Usage: '$0' {start|stop|restart|graceful}" >&2

exit 64

;;

esac

exit 0

Copy the above script to /etc/init.d/httpd file or write your own startup script for apache httpd.

Give the file execute permission

chmod +x /etc/init.d/httpd

Add httpd as service at required run levels

chkconf -add httpd

chkconfig -level 345 httpd on

Now to test the set up try

service httpd start

Starting httpd:                                         [ OK ]

Try http://[ip]:[mod_clusterport]/mod_cluster_manager in the browser.

You should be able to see the following window

Step 5. Convert virtual machine to template
To avoid repeating the same steps for creating httpd virtual machine, you can create the clone of the vm. For vmware powerOff the virtual machine and clone it to template

Now we will look into how to create the jboss image.

Creating JBoss image
Step 1. Create the Centos vm

Refer image creation for httpd

Step 2. Install Java
You can get the latest Java from the following location and the second link explains steps for java installation.

http://www.oracle.com/technetwork/java/javase/downloads/index.html

http://www.oracle.com/technetwork/java/javase/index-137561.html

Step 3. Installing JBoss AS with mod_cluster

We are using JBoss 5.1GA which can be obtained here. Let $JBOSS_HOME is the JBoss installation directory. For installing jBoss AS simply extract the downloaded tar file.

For the demo JBOSS_HOME = /home /JBoss-5.1.0.GA

Download the latest java bundles for mod_cluster here. mod_cluster 1.1.0 work with with JBoss AS 5.1 with out of box.Extract the mod_cluster-1.1.0.xxx-bin.tar.gz file and copy the mod_cluster.sar to the deploy folder.

tar xvf mod_cluster-1.1.0.CR3-bin.tar.gz

cp -r /tmp/mod_cluster.sar $JBOSS_HOME/server/all/deploy

Assuming you have extracted to /tmp directory

cp -r /tmp/mod_cluster.sar $JBOSS_HOME/server/all/deploy

Step 4. Configuration

The main configuration file is mod_cluster-JBoss-beans.xml under

$JBOSS_HOME /server/all/deploy/ mod_cluster.sar/ META-INF/

By default mod_cluster is configured to work in clustered mode. In clustered mode, a single JBoss node is responsible for providing the entire cluster view to the front-end httpd processes.  The default configuration uses advertise mechanism using the mod_advertise module.

Step 5. JBoss as a service at startup

Execute the following commands to add new user jboss and give the startup file execute permission.

#create and give permissions to user jboss

adduser jboss

chown -Rf jboss.jboss /$JBOSS_HOME

#copy the default startup script to /etc/init.d

cd /$JBOSS_HOME /bin

cp JBoss_init_redhat.sh /etc/init.d/jboss

chmod +x /etc/init.d/jboss

Modify the /etc/init.d/jboss file to point JBOSS_HOME and JAVAPTH to point to the actual installed directories.

# chkconfig: - 35 90

# description: JBoss Start|Restart|Stop Application Server

# pidfile: /var/run/JBoss.pid

....

JBOSS_HOME=${JBOSS_HOME:-"$JBOSS_HOME"}

#define the user under which JBoss will run, or use 'RUNASIS' to run as the current user

JBOSS_USER=${JBOSS_USER:-"JBoss"}

#make sure java is in your path

JAVAPTH=${JAVAPTH:-"jdk installation folder "}

#configuration to use, usually one of 'minimal', 'default', 'all'

JBOSS_CONF=${JBOSS_CONF:-"all"}

#if JBOSS_HOST specified, use -b to bind JBoss services to that address

OS=`uname`

IP="" # store IP

case $OS in

Linux) IP=`ifconfig eth0| grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;

FreeBSD|OpenBSD) IP=`ifconfig eth0 | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;

SunOS) IP=`ifconfig -a eth0 | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;

*) IP="Unknown";;

Esac

#Bind to the current ip address

JBOSS_HOST=$IP

JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}

The above modification is to bind jboss to the ip address of the jboss instance.

To add jboss as a service at startup,

#command to start jboss at runlevel 3,4 and 5

chkconfig --add jboss

chkconfig --level 345 jboss on

service jboss start

Check in the browser if JBoss is started

http://[jboss-ip]:8080

Step 6. Convert vm to template

For vmware powerOff the virtual machine and clone it to template.

Testing the environment
Create virtual machines from the above created templates using vijava api or vCenter client. After one instance of both apache httpd and jboss got powered on, check the mod_cluster_manager using the url,

http://[webserverip]:[mod_clusterport]/mod_cluster_manager/

We can see that the JBoss worker is balanced by the mod_cluster. If we create one more JBoss instance, the new one will get added to that balancer. So if you have an application deployed on both of the JBoss instances, the requests will be distributed across the JBoss instances. Similarly when you start up new JBoss instances, the instances will get registered automatically to the proxy and become available for load balancing.If we kill a JBoss instance that will automatically get de-registered from the proxy balancer.

Set up in an environment where multicast is not supported
The above setup showed mod_cluster configuration using advertise mechanism, which uses muticast pings for auto discovery. But major cloud providers like Amazon EC2, Rackspace, GoGrid etc doesn't support multicast in their environment. To overcome this, information about the proxies can be passed through an JBoss argument (JBoss.mod_cluster.proxyList) at start instance up or use the addProxy method exposed by mod_cluster through JMX. The addProxy method takes the IP of httpd proxy and the port on which mod_cluster is listening. You can go to the JBoss AS JMX-Console to do this or use the java code to invoke this method remotely.

To disable the advertise mechanism following configuration changes need to be done :

At httpd side : Set the ServerAdvertise property to off in httpd.conf config file in /opt/JBoss/httpd/httpd/conf

ServerAdvertise off

At JBoss Side : Set advertise property in ModClusterConfig bean to false in mod_cluster-JBoss-beans.xml under $JBOSS_HOME /server/all/deploy/ mod_cluster.sar/ META-INF/

<property name="advertise">false</property>

After setting these properties, create virtual machines from the templates. We can see in the mod_cluster_manger of the apache instance that that jboss node is not added. Now  we have to add the proxy instance to the jboss mod_cluster configuration through JMX. The following code snippet can be used to add a proxy to the balancer.

Hashtable contextProps = new Hashtable();

contextProps.put("java.naming.factory.initial"," org.JBoss.naming.HttpNamingContextFactory");

contextProps.put("java.naming.provider.url", http://+JBossinstanceip+":8080/invoker/JNDIFactory");

contextProps.put("java.naming.factory.url.pkgs", "org.JBoss.naming.client");

InitialContext ctx = new InitialContext(contextProps);  // From table

MBeanServerConnection server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");

Object op = server.invoke(new ObjectName("JBoss.web:service=ModCluster"), "addProxy", new Object[]{webServerIP,webServermod_clusterPort},new String[]{"java.lang.String","int"} );

Now if you check the mod_cluster_manager we can see that the jboss node now balanced by mod_cluster.

Conclusion
With capabilities like dynamic addition of workers without any configuration changes, knowledge of deployed applications and calculation of the real time load balancing factor based on different metrics , it is certain that mod_cluster is the future of load balancer modules for apache and it will also have a huge impact in the cloud environment.

More Stories By Joel Mathew

Joel Mathew works as a Technology Analyst at SETLabs, R&D division, at Infosys Technologies Ltd. He has close to 3 years of experience in development of Cloud computing, Java and Java EE applications, Web 2.0,etc.

@ThingsExpo Stories

ARMONK, N.Y., Nov. 20, 2014 /PRNewswire/ --  IBM (NYSE: IBM) today announced that it is bringing a greater level of control, security and flexibility to cloud-based application development and delivery with a single-tenant version of Bluemix, IBM's platform-as-a-service. The new platform enables developers to build ap...

The BPM world is going through some evolution or changes where traditional business process management solutions really have nowhere to go in terms of development of the road map. In this demo at 15th Cloud Expo, Kyle Hansen, Director of Professional Services at AgilePoint, shows AgilePoint’s unique approach to dealing with this market circumstance by developing a rapid application composition or development framework.
"BSQUARE is in the business of selling software solutions for smart connected devices. It's obvious that IoT has moved from being a technology to being a fundamental part of business, and in the last 18 months people have said let's figure out how to do it and let's put some focus on it, " explained Dave Wagstaff, VP & Chief Architect, at BSQUARE Corporation, in this SYS-CON.tv interview at @ThingsExpo, held Nov 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
The major cloud platforms defy a simple, side-by-side analysis. Each of the major IaaS public-cloud platforms offers their own unique strengths and functionality. Options for on-site private cloud are diverse as well, and must be designed and deployed while taking existing legacy architecture and infrastructure into account. Then the reality is that most enterprises are embarking on a hybrid cloud strategy and programs. In this Power Panel at 15th Cloud Expo (http://www.CloudComputingExpo.com), moderated by Ashar Baig, Research Director, Cloud, at Gigaom Research, Nate Gordon, Director of T...
The Internet of Things is not new. Historically, smart businesses have used its basic concept of leveraging data to drive better decision making and have capitalized on those insights to realize additional revenue opportunities. So, what has changed to make the Internet of Things one of the hottest topics in tech? In his session at @ThingsExpo, Chris Gray, Director, Embedded and Internet of Things, discussed the underlying factors that are driving the economics of intelligent systems. Discover how hardware commoditization, the ubiquitous nature of connectivity, and the emergence of Big Data a...
SYS-CON Events announced today that Windstream, a leading provider of advanced network and cloud communications, has been named “Silver Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place on June 9–11, 2015, at the Javits Center in New York, NY. Windstream (Nasdaq: WIN), a FORTUNE 500 and S&P 500 company, is a leading provider of advanced network communications, including cloud computing and managed services, to businesses nationwide. The company also offers broadband, phone and digital TV services to consumers primarily in rural areas.
“In the past year we've seen a lot of stabilization of WebRTC. You can now use it in production with a far greater degree of certainty. A lot of the real developments in the past year have been in things like the data channel, which will enable a whole new type of application," explained Peter Dunkley, Technical Director at Acision, in this SYS-CON.tv interview at @ThingsExpo, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that IDenticard will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. IDenticard™ is the security division of Brady Corp (NYSE: BRC), a $1.5 billion manufacturer of identification products. We have small-company values with the strength and stability of a major corporation. IDenticard offers local sales, support and service to our customers across the United States and Canada. Our partner network encompasses some 300 of the world's leading systems integrators and security s...
DevOps Summit 2015 New York, co-located with the 16th International Cloud Expo - to be held June 9-11, 2015, at the Javits Center in New York City, NY - announces that it is now accepting Keynote Proposals. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait for long development cycles that produce software that is obsolete at launch. DevOps may be disruptive, but it is essential.
"People are a lot more knowledgeable about APIs now. There are two types of people who work with APIs - IT people who want to use APIs for something internal and the product managers who want to do something outside APIs for people to connect to them," explained Roberto Medrano, Executive Vice President at SOA Software, in this SYS-CON.tv interview at Cloud Expo, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
Nigeria has the largest economy in Africa, at more than US$500 billion, and ranks 23rd in the world. A recent re-evaluation of Nigeria's true economic size doubled the previous estimate, and brought it well ahead of South Africa, which is a member (unlike Nigeria) of the G20 club for political as well as economic reasons. Nigeria's economy can be said to be quite diverse from one point of view, but heavily dependent on oil and gas at the same time. Oil and natural gas account for about 15% of Nigera's overall economy, but traditionally represent more than 90% of the country's exports and as...
The Internet of Things is a misnomer. That implies that everything is on the Internet, and that simply should not be - especially for things that are blurring the line between medical devices that stimulate like a pacemaker and quantified self-sensors like a pedometer or pulse tracker. The mesh of things that we manage must be segmented into zones of trust for sensing data, transmitting data, receiving command and control administrative changes, and peer-to-peer mesh messaging. In his session at @ThingsExpo, Ryan Bagnulo, Solution Architect / Software Engineer at SOA Software, focused on desi...
"At our booth we are showing how to provide trust in the Internet of Things. Trust is where everything starts to become secure and trustworthy. Now with the scaling of the Internet of Things it becomes an interesting question – I've heard numbers from 200 billion devices next year up to a trillion in the next 10 to 15 years," explained Johannes Lintzen, Vice President of Sales at Utimaco, in this SYS-CON.tv interview at @ThingsExpo, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
"For over 25 years we have been working with a lot of enterprise customers and we have seen how companies create applications. And now that we have moved to cloud computing, mobile, social and the Internet of Things, we see that the market needs a new way of creating applications," stated Jesse Shiah, CEO, President and Co-Founder of AgilePoint Inc., in this SYS-CON.tv interview at 15th Cloud Expo, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that Gridstore™, the leader in hyper-converged infrastructure purpose-built to optimize Microsoft workloads, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Gridstore™ is the leader in hyper-converged infrastructure purpose-built for Microsoft workloads and designed to accelerate applications in virtualized environments. Gridstore’s hyper-converged infrastructure is the industry’s first all flash version of HyperConverged Appliances that include both compute and storag...
Today’s enterprise is being driven by disruptive competitive and human capital requirements to provide enterprise application access through not only desktops, but also mobile devices. To retrofit existing programs across all these devices using traditional programming methods is very costly and time consuming – often prohibitively so. In his session at @ThingsExpo, Jesse Shiah, CEO, President, and Co-Founder of AgilePoint Inc., discussed how you can create applications that run on all mobile devices as well as laptops and desktops using a visual drag-and-drop application – and eForms-buildi...
We certainly live in interesting technological times. And no more interesting than the current competing IoT standards for connectivity. Various standards bodies, approaches, and ecosystems are vying for mindshare and positioning for a competitive edge. It is clear that when the dust settles, we will have new protocols, evolved protocols, that will change the way we interact with devices and infrastructure. We will also have evolved web protocols, like HTTP/2, that will be changing the very core of our infrastructures. At the same time, we have old approaches made new again like micro-services...
Code Halos - aka "digital fingerprints" - are the key organizing principle to understand a) how dumb things become smart and b) how to monetize this dynamic. In his session at @ThingsExpo, Robert Brown, AVP, Center for the Future of Work at Cognizant Technology Solutions, outlined research, analysis and recommendations from his recently published book on this phenomena on the way leading edge organizations like GE and Disney are unlocking the Internet of Things opportunity and what steps your organization should be taking to position itself for the next platform of digital competition.
The 3rd International Internet of @ThingsExpo, co-located with the 16th International Cloud Expo - to be held June 9-11, 2015, at the Javits Center in New York City, NY - announces that its Call for Papers is now open. The Internet of Things (IoT) is the biggest idea since the creation of the Worldwide Web more than 20 years ago.
As the Internet of Things unfolds, mobile and wearable devices are blurring the line between physical and digital, integrating ever more closely with our interests, our routines, our daily lives. Contextual computing and smart, sensor-equipped spaces bring the potential to walk through a world that recognizes us and responds accordingly. We become continuous transmitters and receivers of data. In his session at @ThingsExpo, Andrew Bolwell, Director of Innovation for HP's Printing and Personal Systems Group, discussed how key attributes of mobile technology – touch input, sensors, social, and ...