Tuesday, August 13, 2013

How load balancing works in oracle ?

Load Balancing
Oracle RAC systems provide two types of load balancing for automatic workload management:
* Server load balancing distributes processing workload among Oracle RAC nodes.
* Client load balancing distributes new connections among Oracle RAC nodes so that no one server is overwhelmed with connection requests. For example, when a connection fails over to another node because of hardware failure, client load balancing ensures that the redirected connection requests are distributed among the other nodes in the RAC.
The primary difference between these two methods is that the former method distributes processing and the latter method distributes connection attempts.Lets look in details

Client side load balancing 
Client side load balancing is determined by configuring the tnsnames.ora with multiple address in the description ,with parameter LOAD_BALANCE=yes (can specify 'ON' also) , as in this example .
myrac =
  (DESCRIPTION =
   (LOAD_BALANCE=ON)
   (ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
   (ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
    (CONNECT_DATA =
     (SERVICE_NAME = myrac)
    )
  )

Client load balancing helps distribute new connections in your environment so that no one server is overwhelmed with connection requests. When client load balancing is enabled, connection attempts are made randomly among RAC nodes. Suppose you have the Oracle RAC environment  with multiple Oracle RAC nodes, A, B, C, and D. Without client load balancing enabled, connection attempts may be front-loaded, meaning that most connection attempts would try Node A first, then Node B, and so on until a connection attempt is successful.This creates a situation where Node A and Node B can become overloaded with connection requests. Thus in client side load balancing the client will randomly pick an address to try ,without regards to the availability of the node or to how heavily loaded the node may be.

Server Load Balancing
Server side load balancing is controlled by two parameters LOCAL_LISTENER and REMOTE_LISTENER.By default LOCAL_LISTENER is set to blank . Setting local_listener parameter is mandatory when using a different port rather than default .LOCAL_LISTENER on each node should point to the listener on that node.Oracle database have the ability to automatically register their 
presence with an existing default listener with the help of pmon , or you must specify the init parameter LOCAL_LISTENER for non default listener .

A remote listener is a listener residing on one computer that redirects connections to a database instance on another computer. Remote listeners are typically used in an Oracle Real Application Clusters (Oracle RAC) environment. You can configure registration to remote listeners, such as in the case of Oracle RAC, for dedicated server or shared server environments. The REMOTE_LISTENER parameter in the spfile should be pointing to a TNSNAMES entry on each server mode, which in turn list the IPs and ports of all available listeners in the cluster. DBCA will set these entries up for you if you use it to create your databases (recommended).

The remote_listener parameter is then set to listeners_myrac in the spfile

*.remote_listener='LISTENERS_MYRAC'

In tnsnames.ora you can see entry like this,

LISTENERS_MYRAC =
  (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip )(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip )(PORT = 1521))
  )

There are two types of server-side load balancing: 
Load Based — Server side load balancing redirects connections by default depending on node load. This id default.
Session Based — Session based load balancing takes into account the number of sessions connected to each node and then distributes the connections to balance the number of sessions across the different nodes.

Note:- Use listener_<instance_name> as the alias name for the local listener, and listeners_<servicename> for the remote listener alias.
The way you set the remote listener changed in rac 11.2 , instead of registering with local listener, the database register with SCAN listener.
This approach is similar to above, but the pain of configuring individual nodes/their VIPs in client tnsnames.ora is eliminated. All we need is a Round Robin enabled DNS name resolution and use the SCAN DNS name in the client tnsnames.ora.If you do not use DBCA, you should set the REMOTE_LISTENER database parameter to scan_name:scan_port. 

Server-side load balancing divides the connection load evenly between all available listeners by determining the total number of connections on each listener, and then distributing new user session connection requests to the least loaded listener(s) based on the total number of sessions already connected. While a bit more complex to implement because it requires configuration of multiple listeners, it most definitely helps to even out connections across all available listeners in a database system.

To implement server-side load balancing, at least two listeners must be configured. Also, the REMOTE_LISTENERS initialization parameter must be added to the database’s PFILE or SPFILE so that the database knows to search out the value provided in that parameter in the database server’s TNSNAMES.ORA configuration file. When server-side load balancing is activated, each listener that contributes a listening endpoint communicates with the other listener(s) via each database instance’s PMON process. Oracle then determines how many user connections each listener is servicing, and it will distribute any new connection requests so that the load is balanced evenly across all servers. The entries in TNSNAMES.ORA direct the listeners to share information about the relative load connectivity.
   

No comments:

Post a Comment