資料庫壓力測試
一、用orabm測試資料庫CPU
Orabm通過在使用者指定的並發下運行指定數量的事務來測試系統效能.它主要測試資料庫伺服器的CPU效能和記憶體。
orabm實際上是一堆sql的集合。
orabm可以用在linux/windows/solaris下使用。
orabm不一定需要運行在資料庫所在伺服器上,它可以運行在任何安裝了9i用戶端的終端上。你可以用用戶端串連到遠端資料庫來測試遠端資料庫的效能狀況。
因
為orabm主要測試的是CPU和記憶體,所以應該盡量避免其他因素影響測試,故使用orabm時,為了更好的測試CPU和記憶體的效能,最好把
db_cache_size設成大於200M,這樣,所有的資料都可以放在記憶體中,不會因為物理I/O而使得測試不準確。使用orabm的一個步驟就是把
所有的表和索引都放到data buffer中。
1、下載軟體
orabm是測試CPU得
http://www.linxcel.co.uk/orabm/orabm.tar
2、安裝
安裝主要分7個步驟,分別對應6個sql指令碼和一個匯入資料的小工具。如下所有指令碼除第一個必須用擁有dba許可權的使用者執行外,其他的都可以用建立orabm使用者執行。為了避免麻煩,最好都用system或者sys運行
1) create the ORABM user (assumes TOOLS tablespace, TEMP temporary tablespace)
第
一步是建立orabm使用者,並作相應授權。注意,預設情況下,orabm使用者的預設資料表空間是tools,暫存資料表空間是temp。匯入一個
Warehouses的資料量大概是100M,所以,你應該保證tools資料表空間大於150m,或者建立一個資料表空間,然後修改
orabm_user.sql裡的相關資訊。
sqlplus system/pwd @orabm_user
遠端資料庫使用:
sqlplus
system/pwd@tnsname
@orabm_user
2) create the tables
這一步主要建立orabm測試需要的表。
sqlplus system/pwd @orabm_tab
遠端資料庫使用:
sqlplus
system/pwd@tnsname
@orabm_tag
3) Load the data
匯入測試所需的資料(orabmload在OS的對應版本的bin目錄下)
$ orabmload Warehouses 1
遠端資料庫使用:
如果要測試的是遠端資料庫的話,
windows需要先set local=tnsname,tnsname是在tnsname.ora中配置的遠端資料庫的別名。
UNIX/LIINUX,需要先TWO_TASK=tnsname
$ orabmload Warehouses 1
4) create the indexes
這一步建立索引
sqlplus system/pwd @orabm_ind
遠端資料庫使用:
sqlplus
system/pwd@tnsname
@orabm_ind
5) analyze the tables and indexes
分析表和索引
sqlplus system/pwd @orabm_analyze
遠端資料庫使用:
sqlplus
system/pwd@tnsname
@orabm_analyze
6) create the stress-test PL/SQL procedures
建立壓力測試所需的預存程序
sqlplus system/pwd @orabm_serverside_stress
遠端資料庫使用:
sqlplus
system/pwd@tnsname
@orabm_serverside_stress
7) cache the table and index data in the SGA
把表和索引都放到SGA中,原因在上文已經介紹了。
sqlplus system/pwd @orabm_cache
遠端資料庫使用:
sqlplus
system/pwd@tnsname
@orabm_cache
執行完這7個步驟,orabm的測試環境就算配置完成了。
3、測試
現在我們就可以進行測試了。設定好ORACLE_SID,然後進入到OS對應的版本的bin目錄下:
如果測試本機資料庫:
$ orabm 1 20000
如果測試遠端資料庫,則執行
C:> orabm 1 20000 tnsname
注意不要加"@"
orabm後接2個參數(如果測試遠端壓力則接三個參數)。
第一個參數表示測試多少個並發(對應多個session)
第二個參數表示執行多少個事務(注意:不是所有的並發共執行多少事務,而是每個並發執行的事務數),一般來說,這個值設定為10000
第三個參數是在測試遠端資料庫的時候用的,值為tnsnames.ora配置的遠端資料庫串連的別名
orabm 2 1000
表示用2個並發執行1000個事務
orabm 1,2,6,10 1000
表示分別用1、2、6、19個並發執行1000個事務
執行的結果會列印在螢幕上,同時寫到orabm所在目錄的orabm.<oracle_sid>.log。如果執行多次,則多次的執行結果都會追加到orabm.<oracle_sid>.log中。
TPS 是Transactions Per Second 的 縮 寫, 也 就 是 事 務 數/ 秒
tps的計算:每一個階段所有session的tps相加就是當前測試的總tps了。
下面是一個測試執行個體:
環境配置如下:
CPU P4 2.6
MEM: 1G
OS: WINDOWS XP SP2
DATABASE: 9201
SGA:300M
LOGFILE: 100M
LOG_BUFFER: 3M
D:programeroracle tools壓力orabmbinwindows>orabm 1,2,6,10,15,20,25,30 1000
0
---begin sess=1 txn=10000 ORACLE_SID=oracle9i Wed Sep 20 17:47:54 2006
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=15 tps=533 sl=3966(49.6%) on=2478(31
%) oi=1555(19.4%) end=200906-17:48:13
---end - Wed Sep 20 17:48:13 2006
---begin sess=2 txn=10000 ORACLE_SID=oracle9i Wed Sep 20 17:48:13 2006
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=28 tps=286 sl=3933(49.2%) on=2436(30
.5%) oi=1630(20.4%) end=200906-17:48:48
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=28 tps=286 sl=3925(49.1%) on=2422(30
.3%) oi=1652(20.7%) end=200906-17:48:48
---end - Wed Sep 20 17:48:48 2006
---begin sess=6 txn=10000 ORACLE_SID=oracle9i Wed Sep 20 17:48:48 2006
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=80 tps=100 sl=3978(49.7%) on=2415(30
.2%) oi=1606(20.1%) end=200906-17:50:28
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=77 tps=104 sl=4016(50.2%) on=2417(30
.2%) oi=1566(19.6%) end=200906-17:50:29
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=79 tps=101 sl=4078(51%) on=2374(29.7
%) oi=1547(19.3%) end=200906-17:50:29
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=86 tps=93 sl=3993(49.9%) on=2376(29.
7%) oi=1630(20.4%) end=200906-17:50:31
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=84 tps=95 sl=4049(50.6%) on=2321(29%
) oi=1629(20.4%) end=200906-17:50:31
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=86 tps=93 sl=3963(49.5%) on=2420(30.
3%) oi=1616(20.2%) end=200906-17:50:31
---end - Wed Sep 20 17:50:31 2006
---begin sess=10 txn=10000 ORACLE_SID=oracle9i Wed Sep 20 17:50:31 2006
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=112 tps=71 sl=4005(50.1%) on=2391(29
.9%) oi=1603(20%) end=200906-17:52:54
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=126 tps=63 sl=3994(49.9%) on=2433(30
.4%) oi=1572(19.7%) end=200906-17:53:05
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=125 tps=64 sl=3979(49.7%) on=2470(30
.9%) oi=1550(19.4%) end=200906-17:53:09
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=131 tps=61 sl=4030(50.4%) on=2361(29
.5%) oi=1608(20.1%) end=200906-17:53:13
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=134 tps=60 sl=3992(49.9%) on=2390(29
.9%) oi=1617(20.2%) end=200906-17:53:14
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=135 tps=59 sl=3998(50%) on=2352(29.4
%) oi=1649(20.6%) end=200906-17:53:15
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=138 tps=58 sl=3962(49.5%) on=2421(30
.3%) oi=1616(20.2%) end=200906-17:53:17
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=138 tps=58 sl=3999(50%) on=2412(30.2
%) oi=1588(19.9%) end=200906-17:53:17
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=136 tps=59 sl=3988(49.9%) on=2484(31
.1%) oi=1527(19.1%) end=200906-17:53:18
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=143 tps=56 sl=3992(49.9%) on=2365(29
.6%) oi=1642(20.5%) end=200906-17:53:18
---end - Wed Sep 20 17:53:18 2006
---begin sess=15 txn=10000 ORACLE_SID=oracle9i Wed Sep 20 17:53:18 2006
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=168 tps=48 sl=4029(50.4%) on=2377(29
.7%) oi=1593(19.9%) end=200906-17:56:51
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=170 tps=47 sl=4023(50.3%) on=2406(30
.1%) oi=1570(19.6%) end=200906-17:56:52
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=172 tps=47 sl=3932(49.2%) on=2484(31
.1%) oi=1583(19.8%) end=200906-17:57:01
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=191 tps=42 sl=4014(50.2%) on=2461(30
.8%) oi=1524(19.1%) end=200906-17:57:17
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=198 tps=40 sl=3993(49.9%) on=2396(30
%) oi=1610(20.1%) end=200906-17:57:19
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=192 tps=42 sl=4000(50%) on=2392(29.9
%) oi=1607(20.1%) end=200906-17:57:19
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=202 tps=40 sl=3996(50%) on=2390(29.9
%) oi=1613(20.2%) end=200906-17:57:21
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=195 tps=41 sl=4023(50.3%) on=2365(29
.6%) oi=1611(20.1%) end=200906-17:57:21
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=200 tps=40 sl=3962(49.5%) on=2411(30
.1%) oi=1626(20.3%) end=200906-17:57:21
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=203 tps=39 sl=4039(50.5%) on=2385(29
.8%) oi=1575(19.7%) end=200906-17:57:21
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=198 tps=40 sl=3998(50%) on=2406(30.1
%) oi=1595(19.9%) end=200906-17:57:22
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=204 tps=39 sl=4025(50.3%) on=2364(29
.6%) oi=1610(20.1%) end=200906-17:57:22
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=208 tps=38 sl=3944(49.3%) on=2475(30
.9%) oi=1580(19.8%) end=200906-17:57:23
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=201 tps=40 sl=3944(49.3%) on=2448(30
.6%) oi=1607(20.1%) end=200906-17:57:23
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=217 tps=37 sl=3960(49.5%) on=2451(30
.6%) oi=1588(19.9%) end=200906-17:57:24
---end - Wed Sep 20 17:57:24 2006
---begin sess=20 txn=10000 ORACLE_SID=oracle9i Wed Sep 20 17:57:24 2006
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=208 tps=38 sl=4033(50.4%) on=2308(28
.9%) oi=1658(20.7%) end=200906-18:01:49
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=254 tps=31 sl=4093(51.2%) on=2382(29
.8%) oi=1524(19.1%) end=200906-18:02:41
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=257 tps=31 sl=3988(49.9%) on=2416(30
.2%) oi=1595(19.9%) end=200906-18:02:41
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=252 tps=32 sl=4088(51.1%) on=2375(29
.7%) oi=1536(19.2%) end=200906-18:02:42
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=260 tps=31 sl=3970(49.6%) on=2422(30
....
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=272 tps=29 sl=4005(50.1%) on=2402(30
%) oi=1592(19.9%) end=200906-18:02:55
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=280 tps=29 sl=4002(50%) on=2420(30.3
%) oi=1577(19.7%) end=200906-18:02:55
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=276 tps=29 sl=3981(49.8%) on=2428(30
.4%) oi=1590(19.9%) end=200906-18:02:56
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=289 tps=28 sl=3974(49.7%) on=2399(30
%) oi=1626(20.3%) end=200906-18:02:56
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=276 tps=29 sl=4027(50.3%) on=2379(29
.7%) oi=1593(19.9%) end=200906-18:02:56
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=272 tps=29 sl=4031(50.4%) on=2399(30
%) oi=1569(19.6%) end=200906-18:02:56
---end - Wed Sep 20 18:02:56 2006
---begin sess=25 txn=10000 ORACLE_SID=oracle9i Wed Sep 20 18:02:56 2006
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=235 tps=34 sl=3996(50%) on=2414(30.2
%) oi=1589(19.9%) end=200906-18:07:56
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=242 tps=33 sl=3997(50%) on=2408(30.1
%) oi=1594(19.9%) end=200906-18:07:57
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=308 tps=26 sl=4058(50.7%) on=2387(29
.8%) oi=1554(19.4%) end=200906-18:09:16
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=305 tps=26 sl=3959(49.5%) on=2433(30
.4%) oi=1607(20.1%) end=200906-18:09:17
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=307 tps=26 sl=4051(50.6%) on=2387(29
.8%) oi=1561(19.5%) end=200906-18:09:26
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=327 tps=24 sl=3972(49.7%) on=2444(30
.6%) oi=1583(19.8%) end=200906-18:09:26
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=330 tps=24 sl=4022(50.3%) on=2387(29
.8%) oi=1590(19.9%) end=200906-18:09:27
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=312 tps=26 sl=3973(49.7%) on=2413(30
.2%) oi=1613(20.2%) end=200906-18:09:29
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=320 tps=25 sl=4050(50.6%) on=2378(29
.7%) oi=1571(19.6%) end=200906-18:09:30
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=314 tps=25 sl=4005(50.1%) on=2366(29
.6%) oi=1628(20.4%) end=200906-18:09:30
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=314 tps=25 sl=4005(50.1%) on=2366(29
.6%) oi=1628(20.4%) end=200906-18:09:30
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=332 tps=24 sl=3965(49.6%) on=2409(30
.1%) oi=1625(20.3%) end=200906-18:09:30
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=317 tps=25 sl=3997(50%) on=2424(30.3
%) oi=1578(19.7%) end=200906-18:09:32
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=316 tps=25 sl=3970(49.6%) on=2384(29
.8%) oi=1645(20.6%) end=200906-18:09:33
....
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=350 tps=23 sl=3966(49.6%) on=2449(30
.6%) oi=1584(19.8%) end=200906-18:09:41
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=350 tps=23 sl=4030(50.4%) on=2328(29
.1%) oi=1641(20.5%) end=200906-18:09:42
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=353 tps=23 sl=4027(50.3%) on=2414(30
.2%) oi=1558(19.5%) end=200906-18:09:43
---end - Wed Sep 20 18:09:43 2006
---begin sess=30 txn=10000 ORACLE_SID=oracle9i Wed Sep 20 18:09:43 2006
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=286 tps=28 sl=3942(49.3%) on=2392(29
.9%) oi=1665(20.8%) end=200906-18:15:35
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=288 tps=28 sl=4001(50%) on=2396(30%)
oi=1602(20%) end=200906-18:15:44
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=286 tps=28 sl=3912(48.9%) on=2444(30
.6%) oi=1643(20.5%) end=200906-18:15:51
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=373 tps=21 sl=4007(50.1%) on=2408(30
.1%) oi=1584(19.8%) end=200906-18:17:24
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=372 tps=22 sl=4012(50.2%) on=2375(29
.7%) oi=1612(20.2%) end=200906-18:17:25
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=371 tps=22 sl=3987(49.8%) on=2386(29
....
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=384 tps=21 sl=4020(50.3%) on=2389(29
.9%) oi=1590(19.9%) end=200906-18:17:44
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=395 tps=20 sl=4002(50%) on=2418(30.2
%) oi=1579(19.7%) end=200906-18:17:44
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=394 tps=20 sl=4037(50.5%) on=2406(30
.1%) oi=1556(19.5%) end=200906-18:17:45
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=390 tps=21 sl=3959(49.5%) on=2389(29
.9%) oi=1651(20.6%) end=200906-18:17:45
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=395 tps=20 sl=3978(49.7%) on=2409(30
.1%) oi=1612(20.2%) end=200906-18:17:47
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=409 tps=20 sl=3988(49.9%) on=2393(29
.9%) oi=1618(20.2%) end=200906-18:17:49
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=391 tps=20 sl=4005(50.1%) on=2407(30
.1%) oi=1587(19.8%) end=200906-18:17:51
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=387 tps=21 sl=4024(50.3%) on=2433(30
.4%) oi=1542(19.3%) end=200906-18:17:53
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=394 tps=20 sl=3962(49.5%) on=2407(30
.1%) oi=1630(20.4%) end=200906-18:17:54
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=404 tps=20 sl=3991(49.9%) on=2371(29
.6%) oi=1637(20.5%) end=200906-18:17:54
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=402 tps=20 sl=4066(50.8%) on=2386(29
.8%) oi=1547(19.3%) end=200906-18:17:54
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=409 tps=20 sl=3943(49.3%) on=2545(31
.8%) oi=1511(18.9%) end=200906-18:17:55
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=399 tps=20 sl=4013(50.2%) on=2422(30
.3%) oi=1564(19.6%) end=200906-18:17:55
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=415 tps=19 sl=3964(49.6%) on=2425(30
.3%) oi=1610(20.1%) end=200906-18:17:56
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=415 tps=19 sl=3982(49.8%) on=2408(30
.1%) oi=1609(20.1%) end=200906-18:17:56
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=407 tps=20 sl=4017(50.2%) on=2431(30
.4%) oi=1551(19.4%) end=200906-18:17:56
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=427 tps=19 sl=4024(50.3%) on=2368(29
.6%) oi=1607(20.1%) end=200906-18:17:56
oracle9i txn(all)=10000 xn(sam)=7999 t(sam)=420 tps=19 sl=4000(50%) on=2397(30%)
oi=1602(20%) end=200906-18:17:57
---end - Wed Sep 20 18:17:57 2006
其中:
txn(all)----代表Total transaction Count,總的事務數量.
xn(sam)-----採樣的事務數量
t(sam)------採樣事務啟動並執行時間.
這個結果太亂,我們可以用orabm提供的指令碼orabm_tps.sh格式化一下:
這個指令碼一般在linux才可用,本人的機器在windows下安裝了一些linux加強工具,所以可以正常運行這個指令碼
D:programeroracle tools壓力orabmbin>orabm_tps.sh orabm.oracle9i.log
ORACLE_SID=oracle9i sess=1 tps=500
ORACLE_SID=oracle9i sess=3 tps=576
ORACLE_SID=oracle9i sess=1 tps=533
ORACLE_SID=oracle9i sess=2 tps=572
ORACLE_SID=oracle9i sess=6 tps=586
ORACLE_SID=oracle9i sess=10 tps=609
ORACLE_SID=oracle9i sess=15 tps=620
ORACLE_SID=oracle9i sess=20 tps=610
ORACLE_SID=oracle9i sess=25 tps=631
ORACLE_SID=oracle9i sess=30 tps=632
在執行不要執行其他程式,正常情況下,無論多少個並發,CPU的利用率應該在100%
從結果可以看出,原生tps在610左右。
並非並發數越多,tps就越大,有時候隨著並發的增多,tps反而減小。
如果發現隨著並發的增大,tps並沒有明顯增加,或者反而減小了,則說明已經到了系統的瓶頸了。這個臨界點可以看作是系統的所能承受最大tps了。