![]() |
|
Consider the following example of a bank application.
Using Deploy Tool, open BankDesk.ear available at <install_dir>\server\samples\ejb11\BankDesk\ear\. Click Deploy to deploy the application.
The goal of load balancing is to evenly distribute workload between multiple servers. Deploying an application on a cluster from Console is identical to deploying an application on a standalone server. A server synchronizes the deployment across all nodes that form the cluster.
To balance application request loads, place one or more copies of an application component on multiple servers. Each server is configured as a node of the same cluster, allowing it to find application components on other servers. The Load Balancing and failover mechanisms in a cluster are handled transparently. When deploying an application, it is necessary to decide if the application should be configured for Load Balancing.
To distribute the EJB load among the available EJB nodes, the Web nodes do Load Balancing. This is done by the Naming Service that runs on the Web node. The Naming Service is cluster-aware and keeps track of all EJB nodes in the cluster. When a new IC is requested, the Naming Service does Load Balancing on the available EJB nodes and attaches the context with the target EJB node. All requests or lookups made on that instance of IC are routed to that node. If the target EJB node for the context instance fails, a new target node is selected through Load Balancing. The IC instance gets attached to the new node.
To control Load Balancing in JSP pages, Load Balancing can be used. Consider the following piece of code:
Object someBean = ic.lookup("java:comp/env/ejbs/Mybean1");
Object someOtherBean = ic.lookup("java:comp/env/ejbs/Mybean2");
Context ic = new InitialContext();
Here, the EJBs someBean and someOtherBean are retrieved from the same EJB node. If the code is written as:
Object someBean = ic.lookup("java:comp/env/ejbs/Mybean1");
ic = new InitialContext();
Object someOtherBean = ic.lookup("java:comp/env/ejbs/Mybean2");
Context ic = new InitialContext();
The two beans may not come from the same EJB node. If all the beans come from the same node, the inter-bean calls can use the Fast RMI optimization. Note: Beans constituting a single session are most likely to participate in a transaction. If the beans are distributed, the transaction too is distributed, which consumes more resources making it expensive.
Distributed transactions should be avoided. It is important that a single session uses a single instance of the IC. For example:
Context ic = (Context)ssn.getValue("mycontext");
if(ic == null){ic = new InitialContext(); ssn.putValue("mycontext", ic);}
ic.lookup(.....)
...
HttpSession ssn = request.getSession();
This code ensures that a single user session is always attached to the same EJB node.
| © Pramati Technologies 2007 | Runs on Pramati Server | Feedback | Legal |