配置运行时连接负载均衡
运行时连接负载均衡通过平衡在多dispatcher中的活动连接 提高了连接的性能。在rac中,连接池负载均衡也能平衡多实例间的活动连接数量。因为pmon进程能注册远处的监听,一个监听总是能知道所有的实例和dispatcher,依赖与负载的信息,一个监听决定了连接哪个实例,要是配置了共享server,就决定哪个dispatcher要连接。
对专用server的连接池负载均衡
下面显示了rac有2个实例,sales1和sales2,有相同的服务名sales.us.acme.com,实例sales1和sales2分别在sales1-server和sales2-server上。在2个节点上分别有个名为listener的监听。remote_listener参数已经被配置了来允许服务在2个监听上注册
listener_sales2在tnsnames.ora文件中被解析
listener_sales2=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=sales2-server)(PORT=1521)))
listener_sales1值在tnsnames.ora文件中被解析
listener_sales1=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=sales1-server)(PORT=1521)))
会有下面的操作发生
1sals1和sales2上的pmon进程注册实例到2个监听上,监听动态的更新实例的负载。下面的负载信息被注册
sales1-server | sales2-server | |
---|---|---|
1 Minute Node Load Average | 450 | 200 |
sales1 | sales2 | |
---|---|---|
Number of Connections to Instance | 200 | 150 |
(DESCRIPTION=
(LOAD_BALANCE=on)
(F AILOVER=on)
(ADDRESS=(PROTOCOL=tcp)(HOST=sales1-server)(PORT=1521))
(ADDRESS=(PROTOCOL=tcp)(HOST=sales2-server)(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=sales.us.acme.com)))
Table 13-4 Subparameters of the FAILOVER_MODE Parameter
FAILOVER_MODE Subparameter | Description |
---|---|
Specify a different net service name for backup connections. A backup should be specified when using | |
Specify the type of failover. Three types of Oracle Net failover functionality are available by default to Oracle Call Interface (OCI) applications:
| |
Determines how fast failover occurs from the primary node to the backup node:
| |
| Specify the number of times to attempt to connect after a failover. If Note: If a callback function is registered, then this subparameter is ignored. |
| Specify the amount of time in seconds to wait between connect attempts. If Note: If a callback function is registered, then this subparameter is ignored. |
sales.us.acme.com= (DESCRIPTION= (LOAD_BALANCE=on) (FAILOVER=on) (ADDRESS= (PROTOCOL=tcp) (HOST=sales1-server) (PORT=1521)) (ADDRESS= (PROTOCOL=tcp) (HOST=sales2-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (FAILOVER_MODE= (TYPE=select) (METHOD=basic))))
sales.us.acme.com= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales1-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (FAILOVER_MODE= (TYPE=select) (METHOD=basic) (RETRIES=20) (DELAY=15))))
sales1.us.acme.com= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales1-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_NAME=sales1) (FAILOVER_MODE= (BACKUP=sales2.us.acme.com) (TYPE=select) (METHOD=preconnect)))) sales2.us.acme.com= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales2-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_NAME=sales2) (FAILOVER_MODE= (BACKUP=sales1.us.acme.com) (TYPE=select) (METHOD=preconnect))))
FROM V$SESSION
GROUP BY MACHINE, FAILOVER_TYPE, FAILOVER_METHOD, FAILED_OVER;
primary
— Specifies a connection to the primary instance
secondary
— Specifies a connection to the secondary instance
any
— Specifies a connection to whichever instance has the lowest load, regardless of primary or secondary instance role
在下面的例子中,sales_primary能连接到主实例上,sales_secondry能连接到次实例
sales_primary= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales1-server) (PORT=1521)) (ADDRESS= (PROTOCOL=tcp) (HOST=sales2-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_ROLE=primary))) sales_secondary= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales1-server) (PORT=1521)) (ADDRESS= (PROTOCOL=tcp) (HOST=sales2-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_ROLE=secondary)))
配置instance_name=instane_name及instance_role=any来连接到指定的实例上,不用管它的角色,下面的例子,sales1能连接到sales1-server的实例,sales2能连接到sales2-server的实例上。
sales1=
(DESCRIPTION=
(ADDRESS=
(PROTOCOL=tcp)
(HOST=sales1-server)
(PORT=1521))
(CONNECT_DATA=
(SERVICE_NAME=sales.us.acme.com)
(INSTANCE_ROLE=any)
(INSTANCE_NAME=sales2)
(SERVER=dedicated)))
sales2=
(DESCRIPTION=
(ADDRESS=
(PROTOCOL=tcp)
(HOST=sales2-server)
(PORT=1521))
(CONNECT_DATA=
(SERVICE_NAME=sales.us.acme.com)
(INSTANCE_ROLE=any)
(INSTANCE_NAME=sales2)
(SERVER=dedicated)))
taf提前建立连接
如果taf被配置了,备份的连接可以提前创建到次实例上,初始的备份连接必须要明确的指定,下面的例子中,oracle net连接到sales1-server的监听上,并且提前建立sales2-server的连接。如果sales1-server在连接后失败了,taf转移到sales2-server上,保留select语句
sales1.acme.com= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales1-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_ROLE=primary) (FAILOVER_MODE= (BACKUP=sales2.acme.com) (TYPE=select) (METHOD=preconnect)))) sales2.acme.com= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales2-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_ROLE=secondary)))