Monday Aug 30, 2010

PRLB feature in GlassFish 2.1.1

Currently SGESv2.x supports RMI-IIOP loadbalancing. But this loadbalancing is based on the InitialContext:when a new InitialContext() is created, a load balancing decision is made, binding that InitialContext to a replica, until the replica fails, at which point all requests using that InitialContext fail over to a new replica.
Refer : http://docs.sun.com/app/docs/doc/820-4341/fxxqs?a=view

The PRLB feature aims at addressing the requirement, where for the same EJB object of a stateless session bean, the method calls to the bean needs to be loadbalanced. An EJB instance is represented (in GlassFish) by a dynamic stub, which contains a reference to the endpoints. The loadbalancing of the calls happens in a round robin fashion. The list has the lifetime of the stub and anything
that clears or resets the list starts the PRLB process all over again. Hence, ideally an ejb lookup() would reset the list and restarts the
PRLB process.

Configuration:
In sun-ejb-jar.xml, a new optional boolean child element for the ejb element "per-request-load-balancing" is introduced.If per-request-load-balancing is set to true for a stateless session bean, per request load balancing will be enabled for invocations made through Remote EJB 2.x and 3.x client invocations on that bean. If set to false or not set, per request load balancing will not be enabled for the bean. The per-request-load-balancing element only applies to stateless session beans. Use of the element on other bean types will result in
a deployment error.

For example :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.1.1 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-1.dtd">
<sun-ejb-jar>
<enterprise-beans>
<unique-id>1</unique-id>
<ejb>
.
.
<per-request-load-balancing>true</per-request-load-balancing>
.
.
</ejb>

The sun-ejb-jar.xml needs to be updated as above and EJB jar needs to be redeployed.

As a verification check, you can verify that this is configured properly by looking for the following (FINE, in the CORBA logger) log message when the EJB is loaded:

"Setting per-request-load-balancing policyfor EJB <EJBNAME>"

Important requisites for PRLB feature to work :

  •  The "per-request-load-balancing" property needs to be enabled in sun-ejb-jar.xml


Client Example:

public class EJBClient {
    public static void main(String args[]) {
    :
    :
    :
    try {
    // only one lookup

    Object objref = initContext.lookup("test.cluster.loadbalancing.ejb.TestSessionBeanRemote");
        myGreeterRemote = (TestSessionBeanRemote)PortableRemoteObject.narrow(objref,
                                            TestSessionBeanRemote.class);

    } catch (Exception e) {
    :
    }

    for (int i=0; i < 10; i++ ) {
    // method calls in a loop.
        String theMessage = myGreeterRemote.sayHello(Integer.toString(i));
        System.out.println("got"+": " + theMessage);
        }
    }
}

About

Kalpana Karunamurthi

Search

Categories
Archives
« August 2010
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
31
    
       
Today