您的位置:首页 > 数据库 > Oracle

一个很简单测试oracle压力方法

2015-02-18 21:56 471 查看
今天做了一个简单的测试数据库压力,把东西分享了一下。服务器情况: 操作系统版本:CentOS 5.6 -64 cpu:Intel(R) Xeon(R) CPU X5660 @ 2.80GHz * 24 内存:Mem: 16425876 Swap: 32764556 数据库版本:oracle10gR2 节点个数:2 测试方法如下:通过awr找出测试系统里面消耗比较多sql(可以是IO或者是执行时间)使用python写了如下脚本 #! /usr/bin/python #coding=UTF-8 import cx_Oracle import time def hello(): '''''Hello cx_Oracle示例: 1)打印数据库版本信息. 2)查询表数据.''' conn = cx_Oracle.connect("jscn/jscn@192.168.100.199:1521/jscn") cur = conn.cursor() try: print "Oracle Version:%s" % conn.version print "Table SUB_POLICY rows:" interger = 1 while interger <= 30000000: sql="select * from product PRODUCT_ID= '0lea940'" sql1="select * from productcategory where CATEGORY_ID='xhn6238'" cur.execute(sql) for row in cur: print row time.sleep(1) cur.execute(sql1) for row in cur: print row time.sleep(10) interger = interger + 1 finally: cur.close() conn.close() hello() 这里要首先安装好python和cx_Oracle,关于如何安装这两个软件,可以自己百度,过几天我把我的安装方法写上去。让我么简单看看这个python脚本,如果童鞋们要用这个脚本,只要修改连接串和sql部分就可以了,在这个脚本里面,首先执行"sql",然后休息1秒钟,再执行"sql1"部分,再休息10,这个就是一个循环,一共循环30000000次。友情提醒一下python对空格特别敏感,复制的时候要小心了。如果只是简单执行这一个脚本,那叫什么压力测试呢,这个时候要请其他童鞋协助了,在dos下执行如下命令,win7下面最好使用管理员用户执行。 --切换到脚本所在的目录,执行以下命令 for /L %i in (1,1,50) do start "test %i" python test.py 这个脚本是把这个test.py执行开50个窗口执行。如果想停止,可以执行以下命令taskkill /im python.exe现在让我们来看一下数据库的性能,1、查看节点的连接数,到两个节点上面分别查看数据库的连接数登录到第一个节点,查看python连接数SQL> select count(*) from v$session where program='python.exe' ; COUNT(*)---------- 24登录到第二个节点,查看python连接数SQL> select count(*) from v$session where program='python.exe' ; COUNT(*)---------- 26查看总的连接数SQL> select count(*) from gv$session where program='python.exe' ; COUNT(*)---------- 50 2、查看每个用户的pga分配大小 Select spid ,Value / 1024 / 1024 Mb From V$session s, V$sesstat St, V$statname Sn, V$process p Where St.Sid = s.Sid And St.Statistic# = Sn.Statistic# And Sn.Name Like 'session pga memory' And p.Addr = s.Paddr and s.program='python.exe' Order By Value Desc; SPID MB------------ ----------1936 0.730262751906 0.730262751955 0.730262751940 0.730262751953 0.730262751946 0.730262751934 0.730262751942 0.730262751972 0.730262751959 0.730262751900 0.730262751961 0.730262751970 0.730262751968 0.730262751957 0.730262751902 0.730262751904 0.730262751919 0.730262751938 0.730262751923 0.73026275 SPID MB------------ ----------1921 0.730262751925 0.730262751917 0.730262751910 0.730262751908 0.730262751927 0.73026275这里0.73026275*用户数<pga的大小。 3、查看数据库服务器每个spid对应的内存使用情况(下面举例说明)[oracle@rac2 ~]$ top -p 1936,1906,1955,1940top - 19:30:49 up 11 days, 9:24, 1 user, load average: 0.08, 0.08, 0.03Tasks: 4 total, 0 running, 4 sleeping, 0 stopped, 0 zombieCpu(s): 0.3%us, 0.1%sy, 0.0%ni, 99.6%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%stMem: 16425876k total, 6192932k used, 10232944k free, 422484k buffersSwap: 32764556k total, 344k used, 32764212k free, 3581576k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1936 oracle 15 0 1681m 26m 22m S 0.0 0.2 0:00.13 oracle 1906 oracle 15 0 1681m 26m 22m S 0.0 0.2 0:00.14 oracle 1955 oracle 15 0 1681m 26m 22m S 0.0 0.2 0:00.12 oracle 1940 oracle 15 0 1681m 26m 22m S 0.0 0.2 0:00.15 oracle 这里RES的值*个数<总内存。 呵呵,结束了,简单吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: