Oracle Buffer Cache原理總結(二)

oracle_ace發表於2008-01-07

    由於我們的buffer  cache是基於一種共享記憶體的結構,而且buffer的獲取和修改都不可避免的要對Buffer cache中LRU List進行掃描,在runtime的環境中常常會存在併發程式的併發訪問,由於shared memory type的原因,如果沒有一種封鎖機制,那麼很可能會在多程式併發訪問的時候破壞的buffer cache的記憶體結構和資料,在Oracle中latch是一種低階的序列化的裝置,併發程式在scan LRU List的時候必須獲取latch,這樣一來就起了一個對buffer cache這種共享記憶體結構的保護作用.
 
  這個在多程式併發掃描的時候用於lock我們LRU List的latch就是:
Cache Buffers Lru Chain Latch

  如果我們在runtime環境中發現這個latch的競爭比較激烈,那麼我們可以
  1.Enlarge the buffer cache size.
  2.Increate the count of LRU Latch(_db_block_lru_latches)   Highly not recommanded
  3.Adopt the multi-cached tech(default,recycle, keep)

  通過v$latch檢視,我們可以看到這個cache buffers lru chain latch的狀態

  SQL> select addr,latch#,name,gets,misses,immediate_gets,immediate_misses
  2  from v$latch
  3  where name='cache buffers lru chain';

ADDR         LATCH#
-------- --------- 
NAME                                                                   GETS
---------------------------------------------------------------- ----------
    MISSES IMMEDIATE_GETS IMMEDIATE_MISSES
---------- -------------- ----------------
02216258         93
cache buffers lru chain                                                4782
         1           4076                3  
 
  同時我們還要知道Cache Buffers Lru Chain Latch還有很多子Latch,這個子latch的數量受_db_block_lru_latches這個隱含引數的影響.
 
 SQL> select
  2  x.ksppinm name,
  3  y.ksppstvl value,
  4  y.ksppstdf isdefault,
  5  decode(bitand(y.ksppstvf,7),1,'MODIFIED',4,'SYSTEM_MOD','FALSE') ismod,
  6  decode(bitand(y.ksppstvf,2),2,'TRUE','FALSE') isadj from
  7  sys.x$ksppi x,
  8  sys.x$ksppcv y
  9  where
 10  x.inst_id=userenv('Instance') and
 11  y.inst_id=userenv('Instance') and
 12  x.indx=y.indx and
 13  x.ksppinm like '%_&par%'
 14  order by
 15  translate(x.ksppinm,'_','');
輸入 par 的值:  lru
原值   13: x.ksppinm like '%_&par%'
新值   13: x.ksppinm like '%_lru%'

NAME
----------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
ISDEFAULT ISMOD      ISADJ
--------- ---------- -----
_db_block_lru_latches
8
TRUE      FALSE      FALSE

  在我的環境中,這個_db_block_lru_latches的數量是8個

  我們可以通過v$latch _children這個檢視進一步來檢視子latch的狀態:

  SQL> select addr,child#,name,immediate_gets,immediate_misses from v$latch_children
  2  where name='cache buffers lru chain';

ADDR         CHILD#
-------- ----------
NAME                                                             IMMEDIATE_GETS
---------------------------------------------------------------- --------------
IMMEDIATE_MISSES
----------------
68AB27F4          8
cache buffers lru chain                                                       1
               0

68AB2328          7
cache buffers lru chain                                                       1
               0

ADDR         CHILD#
-------- ----------
NAME                                                             IMMEDIATE_GETS
---------------------------------------------------------------- --------------
IMMEDIATE_MISSES
----------------

68AB1E5C          6
cache buffers lru chain                                                       1
               0

68AB1990          5
cache buffers lru chain                                                       1

ADDR         CHILD#
-------- ----------
NAME                                                             IMMEDIATE_GETS
---------------------------------------------------------------- --------------
IMMEDIATE_MISSES
----------------
               0

68AB14C4          4
cache buffers lru chain                                                       1
               0

68AB0FF8          3

ADDR         CHILD#
-------- ----------
NAME                                                             IMMEDIATE_GETS
---------------------------------------------------------------- --------------
IMMEDIATE_MISSES
----------------
cache buffers lru chain                                                    4995
               3

68AB0B2C          2
cache buffers lru chain                                                       1
               0


ADDR         CHILD#
-------- ----------
NAME                                                             IMMEDIATE_GETS
---------------------------------------------------------------- --------------
IMMEDIATE_MISSES
----------------
68AB0660          1
cache buffers lru chain                                                       1
               0


已選擇8行。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12361284/viewspace-113135/,如需轉載,請註明出處,否則將追究法律責任。

相關文章