library cache mutxt竞争

本文探讨了Oracle 11g中Library Cache Latch的变化,介绍其被Library Cache Mutex取代的原因及如何减少资源竞争。通过调整参数和实验对比,展示了不同场景下Mutex的竞争情况。
11G后library cache latch已经消失,被library cache mutxt替代。
library cache latch的数量是比cpu_count值大的最小质数相同的子latch。
@>show parameter cpu

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- ------------------------------
cpu_count                            integer                8
@>select count(*) from v$latch_children where name='library cache';

  COUNT(*)
----------
        11
在并发比较大的系统,非常容易造成争用。
11G以后,MUTXT的数量默认为131072,一个mutxt保护N个library cache buckets.这在很大程度上减小了争用。
-------------------查看MUTEXT的数量为131072,总共的桶数是4194304
sys@ROSE>set linesize 120
sys@ROSE>col name for a30
sys@ROSE>col value for a20
sys@ROSE>col describ for a60
sys@ROSE>SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2    FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3   WHERE x.inst_id = USERENV ('Instance')
  4     AND y.inst_id = USERENV ('Instance')
  5     AND x.indx = y.indx
  6     AND x.ksppinm LIKE '%&par%'
  7  /
Enter value for par: _kdlu_max_bucket_size

NAME                           VALUE                DESCRIB
------------------------------ -------------------- ------------------------------------------------------------
_kdlu_max_bucket_size          4194304              UTS kdlu bucket size
_kdlu_max_bucket_size_mts      131072               UTS kdlu bucket size for mts

-----------------修改session_cached_cursors为0
sys@ROSE>alter system set session_cached_cursors=20 scope=spfile;

System altered.

sys@ROSE>startup force
ORACLE instance started.

Total System Global Area 8551575552 bytes
Fixed Size                  2243608 bytes
Variable Size            8472495080 bytes
Database Buffers           67108864 bytes
Redo Buffers                9728000 bytes
Database mounted.
Database opened.

----------------SQL文本不同,分别开3个SESSION 执行
declare
a number;
begin
        for i in 1 .. 10000000 loop
        select count(*) into a from wxh_tbd where rownum<2;  
end loop;
end;
/


declare
a number;
begin
        for i in 1 .. 10000000 loop
        select count(*) into a from   wxh_tbd where rownum<3;  
end loop;
end;
/

declare
a number;
begin
        for i in 1 .. 10000000 loop
        select count(*) into a from            wxh_tbd where rownum<4;  
end loop;
end;
/
    SID SPID       EVENT                    
------- ---------- -------------------------
    226 14350      latch: cache buffers chai
    242 14359      latch: cache buffers chai
    210 14341      latch: cache buffers chai
   
-----------------SQL文本有空格的差异,开3个SESSION
declare
a number;
begin
        for i in 1 .. 10000000 loop
        select count(*) into a from wxh_tbd where rownum<2;  
end loop;
end;
/
declare
a number;
begin
        for i in 1 .. 10000000 loop
        select count(*) into a from wxh_tbd    where rownum<2;  
end loop;
end;
/
declare
a number;
begin
        for i in 1 .. 10000000 loop
        select count(*) into a from    wxh_tbd where rownum<2;  
end loop;
end;
/
    SID SPID       EVENT                     
------- ---------- -------------------------
    226 14350      library cache: mutex X   
    242 14359      library cache: mutex X   
    210 14341      library cache: mutex X   
   
    SID SPID       EVENT                    
------- ---------- -------------------------
     66 14178      SQL*Net message to client
    210 14341      cursor: pin S            
    226 14350      cursor: pin S            
    242 14359      library cache: mutex X   
以上测试结果表名,貌似ORACLE是把SQL文本去掉空格,大小写之后分配的bucket,因为这种情况下也产生了mutxt竞争。
而SQL文本完全不一样的,完全不存在竞争MUTXT,因为分配在了不同的BUCKET.
   
-----------------修改session_cached_cursors为20   
sys@ROSE>alter system set session_cached_cursors=20 scope=spfile;

System altered.

sys@ROSE>startup force
ORACLE instance started.

Total System Global Area 8551575552 bytes
Fixed Size                  2243608 bytes
Variable Size            8472495080 bytes
Database Buffers           67108864 bytes
Redo Buffers                9728000 bytes
Database mounted.
Database opened.
-----------------SQL文本相同,开三个SESSION执行文本一摸一样的SQL
declare
a number;
begin
        for i in 1 .. 10000000 loop
        select count(*) into a from wxh_tbd where rownum<2;  
end loop;
end;
/

    SID SPID       EVENT                    
------- ---------- -------------------------
     66 16496      SQL*Net message to client
    242 16680      cursor: pin S            
    226 16671      cursor: pin S            
    194 16662      latch: cache buffers chai        

以上测试结果表名,session_cached_cursors参数值不为空的情况下,PGA保留了指向共享池的对象的LCO指针,使获得MUTXT的时间大大缩小,也就避免了竞争。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22034023/viewspace-701601/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22034023/viewspace-701601/

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值