RAC負載均衡的簡單測試(一)

yangtingkun發表於2007-04-11

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%的機率給每個例項分配新的連線。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4227/viewspace-69236/,如需轉載,請註明出處,否則將追究法律責任。

相關文章