Shared pool latch测试

关于shared pool latch,它起到保护共享池堆结构的作用,为了查找到共享池中的free chunk,检索空闲列,分配适当的chunk都只能在
获得shared pool latch后才能操作。比如hard parse,一条sql解析的时候要分配空间用来存储sql statement等信息。
当多个session同事分配chunk时,为了获得shared pool latch就会发生争用。
另外,hard parse严重时,会发生大量的分割chunk的现象,导致共享池碎片化。会延长在空闲列上查找chunk的时间,导致shared pool latch
竞争。
11g里面shared pool有很多组件,主要的还是包括sql area,library cahce,dictionary cache。
SQL> select count(*) from v$sgastat where pool like'shared pool';
COUNT(*)
----------
750
[@more@]
下面来做实验探究下,hard parse导致的shared pool latch contention;
SQL> show sga
Total System Global Area 322228224 bytes
Fixed Size 1299680 bytes
Variable Size 239078176 bytes
Database Buffers 75497472 bytes
Redo Buffers 6352896 bytes
--Variable Size为228M
--引发6000次的hard parse,并且避免soft parse的影响,创建唯一的sql语句。
SQL> create or replace procedure hard_parse(p_id in number)
2 is
3 v_value number;
4 v_cursor sys_refcursor;
5 begin
6 for id in 1..6000 loop
7 open v_cursor for 'select ' ||p_id|| ' from ' ||
8 rpad(' ',id) || ' test test'|| p_id ||
9 ' where rownum=1';
10 fetch v_cursor into v_value;
11 close v_cursor;
12 end loop;
13 end;
14 /
Procedure created.
--flush shared pool
SQL>alter system flush shared_pool;
System altered.
--在10个session上执行hard parse
SQL> var job_no number;
SQL> begin
2 for id in 1..10 loop
3 dbms_job.submit(:job_no,'hard_parse('||id||');');
4 end loop;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL>exec hard_parse(3);
SQL> l
1 select event,total_waits,time_waited
2 from v$session_event
3 where sid=(select sid from v$mystat where rownum=1)
4* order by 3 desc
SQL> /
EVENT TOTAL_WAITS TIME_WAITED
---------------------------------------------------------------- ----------- -----------
latch: shared pool 1831 2902
events in waitclass Other 564 1334
library cache: mutex X 1327 109
db file sequential read 37 63
latch: row cache objects 14 51
latch: cache buffers chains 4 6
log file sync 5 1
cursor: mutex S 1 1
cursor: mutex X 1 0
SQL*Net message to client 32 0
发生hard parse,为了分配保存SQL信息的chunk,就要检索空闲列,这个操作过程,只能由一个进程独占
shared pool latch,多个session发生hard parse的时候就会发生contention。
其实经过测试加大shared pool会导致latch竞争加剧。oltp系统最好还是使用bind变量。

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

转载于:http://blog.itpub.net/25586587/viewspace-1053953/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值