近日浏览eygle的站点,对其中压力测试的专题很有爱好,于是 多方参考文档后实践了一把,过程记录如下 数据库压力测试 一、用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了。
|