In Sun Java System Application Server 9.1, the functionality of the load balancer is enhanced to provide increased flexibility and ease-of-use through the following features.
Application Server allows changes to the load balancer configuration made from the Admin Console to be automatically sent over the wire to the Web Server configuration directory. With previous versions of Application Server, the load balancer configuration had to be exported and then copied over to the web server configuration directory.
The load balancer enables improved distribution of HTTP requests. The administrator can use an attribute called 'weight' to specify how requests will be proportionately routed to an instance. For example, suppose a cluster has two instances, and the administrator has assigned a weight of 100 to instance x and a weight of 400 to instance y. Now, for every 100 requests, 20 will go to instance x and 80 will go to instance y.
Application Server enables the administrator to define a custom policy for distributing HTTP requests. A custom policy defines the load balancing algorithm that the load balancer plug-in must use. In other words, the Administrator can define which Application Server instance will handle an HTTP request. To use this feature, the administrator needs to develop a shared library, which can, for example, be used to evaluate the headers of incoming requests provided to it and in accordance to some criteria, select the instance that can serve the request. This shared library would be loaded by the load balancer.
The shared library must implement an interface as defined in loadbalancer.h, which is available under appserver_install_dir/lib/install/templates.
Application Server also bundles a sample module roundrobin.c that implements the basic round robin algorithm. The administrator can use this sample module as a template to build the shared library. This sample module is also available under appserver_install_dir/lib/install/templates.
Copy roundrobin.c from appserver_install_dir/lib/install/templates to a work directory (for example:/home/user/workspacelb).
Compile roundrobin.c with an ANSI C/C++ compiler (for example Sun Studio compiler or GCC). Be sure to build a dynamic shared library and not a static executable.
If you are using Sun Studio CC Compiler, use the following command to compile:
cc -G -I<appserver install dir>/lib/install/templates roundrobin.c -o roundrobin.so
If you are using GCC, compile the shared library with this command:
gcc -shared -I<appserver install dir>/lib/install/templates roundrobin.c -o roundrobin.so
If you encounter a relocation error, compile again using the option "-fPIC." The command will look like this:
gcc -shared -fPIC -I <appserver install dir>/lib/install/templates roundrobin.c -o roundrobin.so
On Microsoft Windows, download the Cygwin utility from http://www.redhat.com/services/custom/cygwin. This utility has GCC bundled with it. Use the following GCC command to create a dynamic link library (dll):
gcc -shared -I<appserver_install_dir>/lib/install/templates roundrobin.c -o roundrobin.dll
Change loadbalancer.xmlto point to the newly built module. This is how loadbalancer.xml will look after the edit.
<cluster name="cluster1" policy="user-defined" policy-module="home/user/workspacelb/roundrobin.so">
Copy roundrobin.so to the web server instance directory.
Start the web server if it is not running or wait till the load balancer is re-configured.