Oracle Redo并行机制解析(二)

2014-11-24 12:39:04 · 作者: · 浏览: 3
6 66560
7 66560
8 66560
...
Private strand的引入为 Oracle的Redo/Undo机制带来很大的变化。每一个Private strand受到一个单独的redo allocation latch保护,每个Private strand作为“私有的”strand只会服务于一个活动事务。获取到了Private strand的用户事务不是在PGA中而是在Private strand生成Redo,当flush private strand或者commit时,Private strand被批量写入log文件中。如果新事务申请不到Private strand的redo allocation latch,则会继续遵循旧的redo buffer机制,申请写入shared strand中。事务是否使用Private strand,可以由x$ktcxb的字段ktcxbflg的新增的第13位鉴定:
SQL代码
HELLODBA.COM>select decode(bitand(ktcxbflg, 4096),0,1,0) used_private_strand, count(*)
2 from x$ktcxb
3 where bitand(ksspaflg, 1) != 0
4 and bitand(ktcxbflg, 2) != 0
5 group by bitand(ktcxbflg, 4096);
USED_PRIVATE_STRAND COUNT(*)
------------------- ----------
1 10
0 1
对于使用Private strand的事务,无需先申请Redo Copy Latch,也无需申请Shared Strand的redo allocation latch,而是flush或commit是批量写入磁盘,因此减少了Redo Copy Latch和redo allocation latch申请/释放次数、也减少了这些latch的等待,从而降低了CPU的负荷。过程如下:
事务开始 -> 申请Private strand的redo allocation latch (申请失败则申请Shared Strand的redo allocation latch) -> 在Private strand中生产Redo Enrey -> Flush/Commit -> 申请Redo Copy Latch -> 服务进程将Redo Entry批量写入Log File -> 释放Redo Copy Latch -> 释放Private strand的redo allocation latch
注意:对于未能获取到Private strand的redo allocation latch的事务,在事务结束前,即使已经有其它事务释放了Private strand,也不会再申请Private strand了。 www.2cto.com
每个Private strand的大小为65K。10g中,shared pool中的Private strands的大小就是活跃会话数乘以65K,而11g中,在shared pool中需要为每个Private strand额外分配4k的管理空间,即:数量*69k。
SQL代码
--10g:
SQL> select * from V$sgastat where name like '%strand%';
POOL NAME BYTES
------------ -------------------------- ----------
shared pool private strands 1198080
HELLODBA.COM>select trunc(value * KSPPSTVL / 100) * 65 * 1024
2 from (select value from v$parameter where name = 'transactions') a,
3 (select val.KSPPSTVL
4 from sys.x$ksppi nam, sys.x$ksppsv val
5 where nam.indx = val.indx
6 AND nam.ksppinm = '_log_private_parallelism_mul') b;
TRUNC(VALUE*KSPPSTVL/100)*65*1024
-------------------------------------
1198080
--11g:
HELLODBA.COM>select * from V$sgastat where name like '%strand%';
POOL NAME BYTES
------------ -------------------------- ----------
shared pool private strands 706560
HELLODBA.COM>select trunc(value * KSPPSTVL / 100) * (65 + 4) * 1024
2 from (select value from v$parameter where name = 'transactions') a,
3 (select val.KSPPSTVL www.2cto.com
4 from sys.x$ksppi nam, sys.x$ksppsv val
5 where nam.indx = val.indx
6 AND nam.ksppinm = '_log_private_parallelism_mul') b;
TRUNC(VALUE*KSPPSTVL/100)*(65+4)*1024
-------------------------------------
706560
Private strand的数量受到2个方面的影响:logfile的大小和活跃事务数量。
参数_log_private_mul指定了使用多少logfile空间预分配给Private strand,默认为5。我们可以根据当前logfile的大小(要除去预分配给log buffer的空间)计算出这一约束条件下能够预分配多少个Private strand:
SQL代码
HELLODBA.COM>select bytes from v$log where status = 'CURRENT';