2 private strand
为了进一步降低redo buffer的冲突,10g引入了private strand机制,这是从shared pool中分配出来的一块内存空间。每一个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的redo allocation latch的事务,在事务结束前,即使已经有其它事务释放了Private strand,也不会再申请Private strand了。
整个事务过程大致如下:
事务开始 -> 申请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
- 12:59:30 sys@ORCL (^ω^) select * from v$sgastat where name like '%strand%';
- POOL NAME BYTES
- ------------------------ --------------- ----------
- shared pool private strands 1198080
- 13:12:31 sys@ORCL (^ω^) select indx,strand_size_kcrfa from x$kcrfstrand where last_buf_kcrfa = '00';
- INDX STRAND_SIZE_KCRFA
- ---------- -----------------
- 2 66560
- 3 66560
- 4 66560
- 5 66560
- 6 66560
- 7 66560
- 8 66560
- 9 66560
- 10 66560
- 11 66560
- 12 66560
- 13 66560
- 14 66560
- 15 66560
- 16 66560
- 17 66560
- 18 66560
- 19 66560
- 已选择18行。
- 14:53:42 sys@ORCL (^ω^) select 66560*18 from dual;
- 66560*18
- ----------
- 1198080
每个Private strand的大小为65K。Private strand的数量受到2个方面的影响:min(logfile的大小,活跃事务数量)
2.1 logfile的大小
参数_log_private_mul指定了使用多少logfile空间预分配给Private strand,默认为5。我们可以根据当前logfile的大小(要除去预分配给log buffer的空间)计算出这一约束条件下能够预分配多少个Private strand。
- 15:27:25 sys@ORCL (^ω^) select bytes from v$log where status='CURRENT';
- BYTES
- ----------
2.2 活跃事务数量
参数_log_private_parallelism_mul用于推算活跃事务数量在最大事务数量中的百分比,默认为10。Private strand的数量不能大于活跃事务的数量。
- 15:37:19 sys@ORCL (^ω^) show parameter transactions
- NAME_COL_PLUS_S TYPE VALUE_COL_PLUS_
- --------------- --------------- ---------------
- transactions integer 187
- transactions_pe integer 5
- r_rollback_segm
- ent
- 15:42:47 sys@ORCL (^ω^) select trunc((select to_number(value) from v$parameter where name = 'transactions') *
- 15:44:33 2 (select to_number(val.KSPPSTVL)
- 15:44:33 3 from sys.x$ksppi nam, sys.x$ksppsv val
- 15:44:33 4 where nam.indx = val.indx
- 15:44:33 5 AND nam.ksppinm = '_log_private_parallelism_mul') / 100 )
- 15:44:33 6 as "calculated private strands"
- 15:44:33 7 from dual;
- calculated private strands
- --------------------------
- 18
- 15:44:35 sys@ORCL (^ω^) select count(1) "actual private strands" from x$kcrfstrand where last_buf_kcrfa = '00';
- actual private strands
- ----------------------
- 18
