日期:2014-05-16  浏览次数:20628 次

Oracle RAC负载均衡的简单测试
Rac环境安装完成之后,打算简单测试一下Oracle RAC的负载均衡功能。


配置负载均衡,需要在客户端的tnsnames.ora中进行配置。

TESTRAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.224)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.225)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = testrac)
)
)

设置了LOAD_BALANCE = yes之后,使用TESTRAC服务名连接数据库时就启动了负载均衡功能。

登陆RAC实例,检查两个实例上的会话连接情况:

SQL> SELECT INST_ID, COUNT(*) FROM GV$SESSION GROUP BY INST_ID;

INST_ID COUNT(*)
---------- ----------
1 31
2 31

下面在客户端连接RAC实例,并检查当前连接的是哪个实例:

SQL> CONN NDMAIN@TESTRAC输入口令: ******已连接。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac1

SQL> CONN NDMAIN@TESTRAC输入口令: ******已连接。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac2

由于两个实例上会话数量相当,所以Oracle在分配连接时,分配给每个实例的概率基本相同。

这是会话连接两次的情况,下面看看当多个会话连接时,Oracle是如何分配的。

SQL> DISC从 Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options 断开

首先断开刚才连接的会话,然后启动4个新的连接,并检查这些连接分布到哪些实例上:

E:>SQLPLUS NDMAIN/NDMAIN@TESTRAC

SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 3月 22 19:15:26 2007

Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options

SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac1

SQL> HOST
Microsoft Windows 2000 [Version 5.00.2195]
(C) 版权所有 1985-2000 Microsoft Corp.

E:>SQLPLUS NDMAIN/NDMAIN@TESTRAC

SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 3月 22 19:15:46 2007

Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options

SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac1

SQL> HOST
Microsoft Windows 2000 [Version 5.00.2195]
(C) 版权所有 1985-2000 Microsoft Corp.

E:>SQLPLUS NDMAIN/NDMAIN@TESTRAC

SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 3月 22 19:16:02 2007

Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options

SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac2

SQL> HOST
Microsoft Windows 2000 [Version 5.00.2195]
(C) 版权所有 1985-2000 Microsoft Corp.

E:>SQLPLUS NDMAIN/NDMAIN@TESTRAC

SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 3月 22 19:16:16 2007

Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production


With the Partitioning, Real Application Clusters, OLAP and Data Mining options

SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac2

可以看到,由于两个实例负载相当,Oracle基本上是按照50%的概率给每个实例分配新的连接。

您所在的位置:组网建网 > 网络优化 > 负载均衡 > Oracle负载均衡配置代码(1)

Oracle负载均衡配置代码(1)

2010-04-21 12:28 佚名 互联网 我要评论() 字号:T |
友情链接: 爱易网 云虚拟主机技术 云服务器技术 程序设计技术 开发网站 APP开发教程
Copyright © 2013-2024 爱易网页 当前在线:387人  网站在1时44分21秒内访问总人数:25181人 当前 17.69%  粤ICP备18100884号-2