oracle数据库的CPU/IO信息采集

  CPU时间采集 git

  从10G开始,oracle引入了时间模型,咱们能够从oracle的角度来看CPU的使用程度 oracle培训 sql

  先说说几个概念 数据库

  db time:oracle数据库消耗的时间,这个范围比较大,包括了CPU使用,等待IO子系统返回,网络处理等 网络

  db cpu:指oracle单纯消耗CPU,作CPU运算的时间,关于IO,网络的等待都不在这个范围内,用它来统计真实CPU的消耗比较准确 并发

  CPU TIME:这个是我取的名字,表示CPU能给你提供的最大时间,好比你有4个cpu/core,那么1小时内,CPU TIME就是4X60分钟 oracle

  我经过一个测试脚原本看看oracle里面关于CPU时间的统计 oop

  #killcpu.sh 测试

  #!/bin/sh spa

  export ORACLE_SID=innodb code

  export ORACLE_HOME=/opt/oracle/products/11.2.0

  $ORACLE_HOME/bin/sqlplus /nolog <<_kof_

  connect iops/iops@innodb

  declare v_count pls_integer := 0;

  begin

  for x in 1..400000000 loop

  for d in 1..400000000 loop

  for c in 1..400000000 loop

  v_count :=mod(c, mod(x,d));

  end loop;

  end loop;

  end loop;

  end;

  /

  _kof_

  测试机器是Intel(R) Xeon(R) CPU E7530的4C6核 CPU,虚拟出来总共是48个core

  killcpu采用24并发,48并发,60并发作测试,每一个10分钟,经过statspack收集信息,按照上面的公式,咱们的cpu time=10min*60 * 48core=28800秒

  最终结果以下(时间单位都是秒):

  并发数 db time db cpu cpu time top显示CPU占用率 LOAD

  24 14066 14064 28800 50 24

  48 27984 27401 28800 100 48

  60 34556 27179 28800 100 57

  从结果能够看出:

  24并发,oracle使用了24个core,总体的CPU占用率在50%,load在24,很是准确,此时db time基本和db cpu一致,由于你干的全部事情,都是在CPU上

  48并发,oracle使用了48个core,CPU使用率达到100%,oracle在多cpu环境下对资源的利用确实很高,此时db time,db cpu,cpu time一致了,CPU在满负荷运转

  60并发,这个时候会发现,db cpu没变,由于CPU已经耗尽,没得涨了,db time如今已经远大于cpu time和db cpu,这说明咱们有一部分的程序根本抢不到CPU,进入了

  等待,load也超过了core数量,达到57

  经过db cpu/db time,咱们能够看出这个数据库是不是CPU使用很重的应用,好比大量的运算,latch争用等,

  若是是一个IO很重的应用,会发现db cpu站的比例会很小

  IO负载统计

  IO表如今两个方面,IOPS和吞吐量,咱们OLTP系统,通常比较关心IOPS,及每一个IO的响应时间,

  之前针对IOPS统计,咱们一直是按照statspack的physical reads+physical writes来统计,这个是很不许确的

  按照文档的解释:

  physical reads:Total number of data blocks read from disk

  这个是按照block读取的数量来统计的,oracle的IO种类有不少,若是是scatter read或者parallel read,一个IO会读取多块的,

  这样计算IOPS会偏大,从新调整后,发现统计出来的曲线和从存储段观察的比较吻合

  9I:

  –IOPS&MBPS

  select sum(iops) as iops,sum(mbps) as mbps

  from (

  select sum(phyrds + phywrts) as IOPS,

  sum(phyblkrd + phyblkwrt) as MBPS

  from (select a.phyrds,a.phywrts,a.phyblkrd * b.block_size / 1024 / 1024 as phyblkrd,a.phyblkwrt * b.BLOCK_SIZE / 1024 / 1024 as phyblkwrt

  from v$filestat a,v$datafile b

  where a.file# = b.file#)

  union all

  select sum(decode(name,’redo writes’,value,’0′)) as IOPS,

  sum(decode(name,’redo size’,value,’0′)) / 1024 / 1024 as MBPS

  from v$sysstat where name in( ‘redo writes’,'redo size’));

  10G/11G

  –IOPS&MBPS

  select sum(decode(name,’physical read IO requests’,value,’physical write IO requests’,value,0)) as iops,

  sum(decode(name,’physical read bytes’,value,’physical write bytes’,value,0)) / 1024 / 1024 as mbps

  from v$sysstat

  where name in (’physical read IO requests’,'physical write IO requests’,

  ‘physical read bytes’,'physical read total bytes’,

  ‘physical write bytes’,'physical write total bytes’,'physical read total IO requests’,'physical write total IO requests’

  );

  最近将这些统计指标作进了监控系统,看看效果怎么样

相关文章
相关标签/搜索