官方的原话:
About Runtime Connection Load Balancing
Runtime Connection Load Balancing is a feature of Oracle connection pools that can distribute client work requests across the instances in an Oracle RAC database based on the Load Balancing Advisory information. The connection allocation is based on the current performance level provided by the database instances as indicated by the Load Balancing Advisory FAN events. This provides load balancing at the transaction level, instead of load balancing at the time of the initial database connection.
With Runtime Connection Load Balancing, applications use Load Balancing Advisory information to provide better performance to users. OCI Session pools and ODP.NET connection pools support Runtime Connection Load Balancing. For Java applications, Oracle recommends the Universal Connection Pool (UCP). The Universal Connection Pool is integrated to take advantage of Load Balancing Advisory information. UCP, introduced in Oracle Database 11g Patchset 1 (11.1.0.7), can be used against Oracle Database 10g or Oracle Database 11g.
You must enable the client data source for Runtime Connection Load Balancing with a service that has the following configuration:
■ The Load Balancing Advisory is enabled and the service-level goal is set to either Service Time or Throughput.
■ The service connection load balancing goal is set to Short.
Figure 7–1, "Runtime Connection Load Balancing" illustrates Runtime Connection Load Balancing. In this illustration, the Oracle RAC database has three instances. Suppose that the Load Balancing Advisory indicates that Instance1 and Instance3 have the best performance, while Instance2 currently has less than optimal performance.
When Runtime Connection Load Balancing is enabled on the implicit connection cache, the following process occurs:
1. A client requests a connection from the connection pool.
2. Runtime Connection Load Balancing selects the connection that belongs to the most efficient (best) instance from the connection pool. In Figure 7–1, there are three possible nodes to which the connection can be routed. Instance1, which has the least amount of CPU workload, is currently being assigned about 60 percent of the incoming connections. Instance2, which is currently overloaded, is only being assigned around 10 percent of the incoming connections. Instance3, which has a high workload, is being assigned around 30 percent of the incoming connections. The best instance to handle the connection request in this case would be Instance1.
3. The client receives the connection that would process the work request with the best response time.
Figure 7–1 Runtime Connection Load Balancing
Oracle Database 11g introduces an additional flag in the load balancing advisory event called affinity hint. The affinity hint is automatic when load balancing advisory is turned on through setting the goal on the service. This flag is for temporary affinity that lasts for the duration of a web session. Web conversations often connect and disconnect a number of times during the entire session. During each of these connects, it may access the same or similar data, for example, a shopping cart, Siebel, and so on. Affinity can improve buffer cache efficiency, which lowers cpu usage and transaction latency. The Affinity Hint is a flag that indicates if Affinity is active or inactive for a particular instance and service combination. Different instances offering the same service can have different settings for the Affinity Hint.
Applications using Oracle Database 11g and UCP, can take advantage of this new affinity feature. If the affinity flag is turned on in the Load Balancing Advisory event, then UCP will create an Affinity Context for the Web session such that when that session does a get connection from the pool, the pool will always try to give it a connection to the instance it connected to the first time it acquired a session. The choice of instance for the first connection is based on the current load balancing advisory information.
总结:
其实Runtime Connection Load Balancing是建立在Connection Load Balancing基础上的,是指从连接池中取得已有连接时的 Connection Load Balancing。
srvctl创建service的时候,需要制定一个参数-B(Goal for the Load Balancing Advisory)。
该参数是:运行时负载均衡,Load Balancing Advisory的子参数,支持事务级别(transaction level)的负载均衡,其三个选项:NONE为关闭,其余两个参数是SERVICE_TIME(适于长时间交易的事务)和THROUGHPUT(适于短时间交易的事务),其含义在官方文档中的解释为:
SERVICE_TIME - The Load Balancing Advisory attempts to direct work requests to instances according to their response time. Load Balancing Advisory data is based on the elapsed time for work done by connections using the service, as well as available bandwidth to the service. This goal is best suited for workloads that require varying lengths of time to complete, for example, an internet shopping system.
THROUGHPUT - The Load Balancing Advisory measures the percentage of the total response time that the CPU consumes for the service. This measures the efficiency of an instance, rather than the response time. This goal is best suited for workloads where each work request completes in a similar amount of time, for example, a trading system.
要启用运行时负载均衡,另外一个参数 -j <clb_goal> 负载均衡的连接目标要设置为SHORT。