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的时间大大缩小,也就避免了竞争。
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/
本文探讨了Oracle 11g中Library Cache Latch的变化,介绍其被Library Cache Mutex取代的原因及如何减少资源竞争。通过调整参数和实验对比,展示了不同场景下Mutex的竞争情况。

被折叠的 条评论
为什么被折叠?



