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


做了一个简单的测试数据库压力,把东西分享了一下。

服务器情况:

    操作系统版本:CentOS 5.6 -64
    cpu:Intel(R) Xeon(R) CPU  X5660  @ 2.80GHz * 24
    内存:Mem:      16425876
          Swap:     32764556
    数据库版本:Oracle10gR2

    节点个数:2 

测试方法如下:通过awr找出测试系统里面消耗比较多sql(可以是IO或者是执行时间)
使用python写了如下脚本
  1. #! /usr/bin/python   
  2. #coding=UTF-8   
  3.   
  4. import cx_Oracle  
  5. import time  
  6.   
  7. def hello():  
  8.     '''''Hello cx_Oracle示例: 
  9.  
  10.     1)打印数据库版本信息. 
  11.     2)查询表数据.'''  
  12.   
  13.     conn = cx_Oracle.connect("jscn/jscn@192.168.100.199:1521/jscn")  
  14.     cur = conn.cursor()  
  15.     try:  
  16.         print "Oracle Version:%s" % conn.version  
  17.         print "Table SUB_POLICY rows:"  
  18.         interger = 1  
  19.         while interger <= 30000000:  
  20.             sql="select * from product PRODUCT_ID= '0lea940'"  
  21.             sql1="select * from productcategory  where CATEGORY_ID='xhn6238'"  
  22.             cur.execute(sql)  
  23.             for row in cur:  
  24.                 print row  
  25.                 time.sleep(1)  
  26.             cur.execute(sql1)  
  27.             for row in cur:  
  28.                 print row  
  29.                 time.sleep(10)                  
  30.             interger = interger + 1  
  31.     finally:  
  32.         cur.close()  
  33.         conn.close()  
  34. hello()  

这里要首先安装好python和cx_Oracle,关于如何安装这两个软件,可以自己百度,过几天我把我的安装方法写上去。
让我么简单看看这个python脚本,如果童鞋们要用这个脚本,只要修改连接串和sql部分就可以了,在这个脚本里面,首先执行"sql",然后休息1秒钟,再执行"sql1"部分,再休息10,这个就是一个循环,一共循环30000000次。
友情提醒一下python对空格特别敏感,复制的时候要小心了。
如果只是简单执行这一个脚本,那叫什么压力测试呢,这个时候要请其他童鞋协助了,在dos下执行如下命令,win7下面最好使用管理员用户执行。
  1. --切换到脚本所在的目录,执行以下命令  
  2. 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分配大小
  1. Select spid ,Value / 1024 / 1024 Mb  
  2.   From V$session s, V$sesstat St, V$statname Sn, V$process p  
  3.  Where St.Sid = s.Sid  
  4.    And St.Statistic# = Sn.Statistic#  
  5.    And Sn.Name Like 'session pga memory'  
  6.    And p.Addr = s.Paddr and s.program='python.exe'    
  7.  Order By Value Desc;  
SPID                 MB
------------ ----------
1936         0.73026275
1906         0.73026275
1955         0.73026275
1940         0.73026275
1953         0.73026275
1946         0.73026275
1934         0.73026275
1942         0.73026275
1972         0.73026275
1959         0.73026275
1900         0.73026275
1961         0.73026275
1970         0.73026275
1968         0.73026275
1957         0.73026275
1902         0.73026275
1904         0.73026275
1919         0.73026275
1938         0.73026275
1923         0.73026275
 
SPID                 MB
------------ ----------
1921         0.73026275
1925         0.73026275
1917         0.73026275
1910         0.73026275
1908         0.73026275
1927         0.73026275
这里0.73026275*用户数<pga的大小。

3、查看数据库服务器每个spid对应的内存使用情况(下面举例说明)
[oracle@rac2 ~]$ top -p 1936,1906,1955,1940
top - 19:30:49 up 11 days,  9:24,  1 user,  load average: 0.08, 0.08, 0.03
Tasks:   4 total,   0 running,   4 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.3%us,  0.1%sy,  0.0%ni, 99.6%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  16425876k total,  6192932k used, 10232944k free,   422484k buffers
Swap: 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的值*个数<总内存。

呵呵,结束了,简单吧。

相关内容