Chapter 4 Working with Load Balancers

This section provides instructions on how to set up the Web Server software
to act as a load balancer to the cluster of Application Servers. In addition,
it provides steps for configuring a load balancer and exporting it to the
Web Server. The load balancer feature is available to you only if you are
running a domain with enterprise profile or cluster profile.

A load balancer is deployed with a cluster. A load balancer provides
the following features:

Allows an application or service to be scaled horizontally
across multiple physical (or logical) hosts yet still presents the user with
a single URL

Insulates the user from host failures or server crashes, when
it is used with session persistence.

Enhances security by hiding the internal network from the
user

Enterprise Server includes load balancing plug-ins for popular web servers
such as Sun JavaTM System Web Server, Apache, and Microsoft
Windows IIS.

To complete this section, you must have sufficient memory to run a Web
Server on your system in addition to the Domain Administration Server and
the two instances you have created so far in this guide. A system with 512
Mbytes to 1024 Mbytes of memory is recommended.

Setting up Load Balancing

Before you set up load balancing, you need to install the load balancer
plug-in. These procedures assume you are running a domain with
cluster or enterprise profile.

To Set Up Load Balancing

Create a load balancer using the Admin Console. Alternatively,
you can use the asadmin create-http-lb(1) command.

Click the HTTP Load Balancers node in the Admin Console.

Click New.

Type lb1 as the name of the load balancer,
the host on which Web Server is installed, and the Web Server instance port.
In this sample scenarios Web Server host is localhost and the port is 38000.

Select the Apply Changes Automatically check box. If you choose
this option, you do not have to export the load balancer configuration. All
changes you make to the load balancer configuration are propagated automatically.

Add a name and value pair (Name=Name Value=Duke)
for storing in HttpSession.

Click the Add to Session Data button.

Verify that the session data was added

High Availability and Failover Using the In-memory
Replication Feature

GlassFish v2 does not offer HADB. For high availability and failover,
GlassFish offers the in-memory replication feature. The following procedure
illustrates this feature:

Restart the web server that has the load balancer plugin installed
before deploying an application. This ensures that requests are served by
instances in the order set in the loadbalancer.xml file.
If you use the loadbalancer.xml file provided in this
chapter, instance1 serves the first request.

You have already deployed the clusterjsp web
application, which stores session data. You should be able to see that successive
requests are served by the same instance that served the first request and
the session data is maintained across the requests.

Send few requests and note down the instance that served those
requests and shutdown that particular instance. Use this command to stop the
instance: asadmin stop-instance --user adminuser --password adminpassword
instance1

Send in the next request and verify that the new data is stored
and that the previously added data is still there in the session. If one of
the server serving requests is not available, another server in the same cluster
takes over the request with all earlier session data and completes the request.