Oracle® Application Server Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 2 (10.1.2) Part No. B15505-01 |
|
![]() Previous |
![]() Next |
Load balancing for EJBs occurs across all OC4J processes included in the cluster.
The client retrieves a random OC4J process when the first lookup is executed. The selection of which OC4J process that services the client is always randomly chosen from among the pooled OC4J processes in the cluster. However, you can choose to have the client do the following:
If you do not set any options, then the client interacts with the OC4J process that was initially chosen at the first lookup for the entire conversation.
If you do set one of two options, then the client chooses another OC4J process with which to interact at specific points in the client's implementation. Each time a client requests another OC4J process, this process is also chosen randomly from the OC4J processes involved in the cluster.
These options are as follows:
LoadBalanceOnLookup
property: If this property is set to true, then the client randomly picks another OC4J process from the pooled processes in the cluster each time a lookup is executed. You should only use RMIInitialContextFactory
object with this option.
The following configures the LoadBalanceOnLookup
property on the client to true in the JNDI properties before retrieving the InitialContext
:
env.put("LoadBalanceOnLookup", "true");
dedicated.rmicontext
property: If this property is set to true, then each time the client retrieves a new InitialContext
, the client also retrieves a new OC4J process. If you want to use multiple OC4J processes within your client, this option is more performant and less burdensome on the application server than the LoadBalanceOnLookup
property.
If you are not interested in EJB state replication, but want to load balance your request among OC4J processes, the following sections describe your options:
If you decide to not use EJB replication, but you want to load balance the request across several OC4J processes, you can use static retrieval by providing the URLs for all of these processes in the JNDI URL property.
The JNDI addresses of all OC4J nodes that should be contacted for load balancing and failover are supplied in the lookup URL, and each address is separated by a comma. For example, the following URL definition provides the client container with three OC4J nodes to use for load balancing and failover.
java.naming.provider.url=ormi://s1:23791/ejbsamples, ormi://s2:23793/ejbsamples, ormi://s3:23791/ejbsamples;
Alternatively, if you do not want to use EJB replications, but you want to load balance the request using DNS for load balancing, you can do the following:
Within DNS, map a single host name to several IP addresses. Each of the port numbers must be the same for each IP address. Set up the DNS server to return the addresses either in a round-robin or random fashion.
The IP address identifies the OC4J running; the port number is an RMI port number.
Turn off DNS caching on the client. For UNIX machines, you must turn off DNS caching as follows:
Kill the NSCD daemon process on the client.
Start the OC4J client with the -Dsun.net.inetaddr.ttl=0
option.
Within each client, use ANY initial context factory to create an initial context. Use the ormi://
prefix in the provider URL. Use the single host name in the DNS server to which the OC4J IP addresses are mapped and the common RMI port in the provider URL for the client.
Set the dedicated.rmicontext
property to true.
Each time the lookup occurs on the DNS server, the DNS server hands back one of the many IP addresses that are mapped to it.
Example 13-1 RMIInitialContextFactory Example
This example uses an RMIInitialContextFactory
object; however, you can use any initial context factory for DNS load balancing. In this example, myserver
is the host name set up in the DNS server for the list of servers, and the RMI port is defaulting to the default port.
java.naming.factory.initial= com.evermind.server.rmi.RMIInitialContextFactory java.naming.provider.url=ormi://myserver/applname java.naming.security.principal=admin java.naming.security.credentials=welcome dedicated.rmicontext=true