计算出linux cache,关于计算buffer cache hit rate的精确算法

在系统运行过程中,如果我们发现Cache hit rate过小,或者我们通过观察statspack中的Instance Efficiency Percentages这部分呢,我们会发现Buffer Hit%的值很低,通常这就是在暗示你要增加DB_CACHE_SIZE了

1.通常的计算方法

可能大家都知道我们一般都是通过以下的公式来计算我们的buffer hit%的

Cache hit rate=((consistent_gets + db_block_gets) - physical_reads) /

(consistent_gets + db_block_gets)

2.进一步更精确的结果,我们需要考虑direct reads

如果Buffer hit%为85%,那么如果只是这样简单的按照上面的公式,计算得到85%的命中率,并不意味着miss rate=15%,因为15%中包括我们通常所说的direct reads。

direct reads一般发生在parallel scans和 reads from temporary tablespaces等情况下。blocks被直接读入私有PGA中的buffer,而没有经过SGA中的buffer cache.所以我们不应该把其算入内.

所以,如果我们通过查询v$sysstat来计算buffer hit%,可以去掉direct物理读部分,这样更新后的公式就是

Buffer hit = 1 - ((physical reads - physical reads direct - physical reads direct (lob)) /

(db block gets + consistent gets - physical reads direct - physical reads direct (lob))

另外,v$sysstat中的consistent_gets的值也有所夸大,可以累加以下4项得到:

no work - consistent read gets

cleanouts only - consistent read gets

rollbacks only - consistent read gets

cleanouts and rollbacks - consistent read gets

其实最好的方法是直接访问V$BUFFER_POOL_STATISTICS而不是v$sysstat,其中的数据都是排除了direct reads的结果。

比如

V$BUFFER_POOL_STATISTICS.physical_reads=v$sysstat 的'physical reads'- 'physical reads direct'- 'physical reads direct (lob)'

这样可以直接运行下面的语句来计算我们的Buffer Hit%:

select name, ((consistent_gets + db_block_gets) - physical_reads) /

(consistent_gets + db_block_gets) * 100 "Hit Ratio%"

from v$buffer_pool_statistics

where physical_reads > 0;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值