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

yangtingkun發表於2007-04-12

Rac環境安裝完成之後,打算簡單測試一下Oracle RAC的負載均衡功能。

這篇繼續討論負載均衡的特性。

RAC負載均衡的簡單測試(一):http://yangtingkun.itpub.net/post/468/279433


上一篇的測試中可以看到,當兩個例項的負載相當的時候,新連線會平均分配到兩個例項上去。

下面看看如果其中一個例項的連線數明顯大於另一個例項的情況。增加連線TESTRAC2例項的連線數,這裡使用的方法是在racnode2資料庫上使用直接連線的方式:

$ sqlplus ndmain

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 19:24:23 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> host
$ sqlplus ndmain

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 19:24:28 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> host
$ sqlplus ndmain

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 19:24:33 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> host
$ sqlplus ndmain

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 19:24:37 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> host
$ sqlplus ndmain

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 19:24:44 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> host
$ sqlplus ndmain

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 19:24:48 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> host
$ sqlplus ndmain

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 19:24:54 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> host
$ sqlplus ndmain

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 19:25:00 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>

查詢目前資料庫的連線情況:

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

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

下面嘗試多次連線,並檢查連線的例項:

SQL> CONN NDMAIN/NDMAIN@TESTRAC已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

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

SQL> CONN NDMAIN/NDMAIN@TESTRAC已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

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

SQL> CONN NDMAIN/NDMAIN@TESTRAC已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

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

SQL> CONN NDMAIN/NDMAIN@TESTRAC已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

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

SQL> CONN NDMAIN/NDMAIN@TESTRAC已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

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

發現連線到兩個例項的機率仍然是一樣的。看看連續啟動多個連線的情況:

E:>SQLPLUS NDMAIN/NDMAIN@TESTRAC

SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 3 22 19:27:05 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:27:18 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:27:31 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:27:40 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

可以看到,結果仍然是50%的機率。難道負載均衡不考慮例項本身的負載,只是對新增連線進行平均分配?

其實並不是這樣,關鍵在於負載均衡的功能是透過LISTENER來實現的。而在上面增加TESTRAC2上的連線數的時候,採用的是本地連線方式,恰恰繞過了LISTENER,對於LISTENER來說,這些新增的會話都是不可見的。因此,得到的結果當然和原來的一致。

下面斷開剛才連線的所有會話:

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

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

然後以TESTRAC2為服務名,連線到RACTESTRAC2例項上:

$ sqlplus ndmain/ndmain@testrac2

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 21:14:44 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> host
$ sqlplus ndmain/ndmain@testrac2

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 21:14:52 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> host
$ sqlplus ndmain/ndmain@testrac2

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 21:14:55 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> host
$ sqlplus ndmain/ndmain@testrac2

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 21:14:59 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> host
$ sqlplus ndmain/ndmain@testrac2

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 21:15:04 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> host
$ sqlplus ndmain/ndmain@testrac2

SQL*Plus: Release 10.2.0.2.0 - Production on 星期四 3 22 21:15:14 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>

再次測試連線例項的情況:

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

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

SQL> CONN NDMAIN/NDMAIN@TESTRAC已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

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

SQL> CONN NDMAIN/NDMAIN@TESTRAC已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

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

SQL> CONN NDMAIN/NDMAIN@TESTRAC已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

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

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
斷開

可以看到,連線時Oracle都會將會話連線到TESTRAC1上。下面看看連續啟動多個會話,Oracle如何在例項間分配會話:

E:>SQLPLUS NDMAIN/NDMAIN@TESTRAC

SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 3 22 21:19:41 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 21:19:59 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 21:20:12 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>

根據上面的測試可以看出,Oracle的負載均衡和例項透過LISTENER建立的連線數有關。

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

相關文章