解决一则row cache lock引起的性能故障

转载的文章地址:http://www.oracleonlinux.cn/2012/06/row-cache-lock-performance-tuning/

 

此文章写的很好,非常详细的解说了cache引起的性能故障。

 

收到紧急邮件:说某客户生产系统在今天早上9:30左右,生产环境整个系统操作响应很慢,查询一票单子可能要耗时半分钟,有时候登录界面也卡住很久才响应

       这是一套10.2.0.5.0的双节点RAC数据库,平时系统运行较为正常,现在突然变慢。好了,对于我这个优化菜鸟来讲,还是从AWR报告入手。下面给出分析步骤和解决办法:

1   从报告头中看到,在数据库出现性能问题的一个小时内,DB Time达到240分钟,(DB Time)/Elapsed=3.93,说明数据库应该是存在问题的。

 

Snap IdSnap TimeSessionsCursors/Session
Begin Snap:1063805-6月 -12 09:00:00545.8
End Snap:1063905-6月 -12 10:01:031025.8
Elapsed:61.04 (mins)61.04 (mins)61.04 (mins)
DB Time: 

 

 

 

 

 

2   从报告的Load Profile节,看到用户的每秒调用高达680次,说明肯定存在问题了。

Load Profile

 

Per SecondPer Transaction
Redo size:12,939.466,115.60
Logical reads:67,323.1831,819.06
Block changes:53.2225.15
Physical reads:1.020.48
Physical writes:4.722.23
User calls:679.70321.25
Parses:90.4942.77
Hard parses:0.350.16
Sorts:1.940.92
Logons:0.080.04
Executes:316.75149.71
Transactions:2.12

3   继续分析报告,从Top 5中看到排在第一的等待事件是row cache lock,并且该等待事件的平均等待达到2128ms。

ROW CACHE LOCK等待事件是一个共享池相关的等待事件,是由于对于字典缓冲的访问造成的。通常直接的解决办可以通过调大共享池来解决,但是,并非在所有场景下都凑效。

Top 5 Timed Events

 

EventWaitsTime(s)Avg Wait(ms)% Total Call TimeWait Class
row cache lock2,7365,8222,12840.4Concurrency
CPU time4,30529.9
gc cr block busy2,2932,6331,14818.3Cluster
gc buffer busy1,5691,0966987.6Cluster
enq: TX - row lock contention2,0299984926.9Application

4    继续分析,发现基于时间的统计信息中,加载序列sequence的耗时排在了第二位。

Time Model Statistics

  • Total time in database user-calls (DB Time): 14406.5s
  • Statistics including the word "background" measure background process time, and so do not contribute to the DB time statistic
  • Ordered by % or DB time desc, Statistic name

 

Statistic NameTime (s)% of DB Time
sql execute elapsed time14,188.0198.48
sequence load elapsed time6,900.8347.90
DB CPU4,304.5929.88
PL/SQL execution elapsed time20.640.14
parse time elapsed10.250.07
hard parse elapsed time6.000.04
PL/SQL compilation elapsed time1.170.01
hard parse (sharing criteria) elapsed time1.070.01
repeated bind elapsed time0.800.01
hard parse (bind mismatch) elapsed time0.640.00
connection management call elapsed time0.310.00
failed parse elapsed time0.000.00
DB time14,406.50
background elapsed time2,115.75
background cpu time20.52

5     看到最耗时的竟然是一条再简单不过的SQL语句,SELECT SEQ_NEWID.NEXTVAL FROM DUAL,取序列的值,竟然会如此的耗时?

SQL ordered by Elapsed Time

  • Resources reported for PL/SQL code includes the resources used by all SQL statements called by the code.
  • % Total DB Time is the Elapsed Time of the SQL statement divided into the Total Database Time multiplied by 100
  • Total DB Time (s): 14,406
  • Captured SQL account for 223.8% of Total

 

Elapsed Time (s)CPU Time (s)ExecutionsElap per Exec (s)% Total DB TimeSQL IdSQL ModuleSQL Text
6,910028124.5947.961gd7ancd2px8mFC.EdiService.Import.exeSELECT SEQ_NEWID.NEXTVAL FROM ...

6    再看字典缓冲区的统计信息:取序列值一共287次,就失败了43.9%,看来的确是取序列值的地方出现问题,也就解释了为什么上一步骤中的分许出的那条SQL会如此耗时,因为差不多有一半的情况下都没有取到序列的值。

Dictionary Cache Stats

  • "Pct Misses" should be very low (< 2% in most cases)
  • "Final Usage" is the number of cache entries being used

 

CacheGet RequestsPct MissScan ReqsFinal UsageMod ReqsPctMiss
dc_awr_control651.54011
dc_database_links3040.00001
dc_global_oids1550.000024
dc_histogram_data74,7040.25005,612
dc_histogram_defs71,4000.26004,945
dc_object_ids29,3980.01001,136
dc_objects3,9120.2300860
dc_profiles1500.00001
dc_rollback_segments17,7890.100056
dc_segments8,9270.0604896
dc_sequences28743.9002793
dc_tablespace_quotas250.00002
dc_tablespaces8,9540.000025
dc_usernames1,0820.00008
dc_users13,9910.000031
outstanding_alerts32677.9102354

7   到此,解决问题的基本思路已经出来了,通过将序列缓存到内存中,基本可以解决问题。通过查看生产系统上的该序列的信息,发现创建序列的语句如下:

1
2
3
4
5
6
7
-- Create sequence
create sequence SEQ_NEWID
minvalue 1000
maxvalue 9999
start with 1000
increment by 1
nocache;

8   调整序列,使之cache到内存中,alter sequence SEQ_NEWID cache 3000;

9   附带,刚在生产系统上把序列cache到内存,另一同事就把RAC数据库给重启了,据他判断说是存储系统出了问题。可是,怎么会是存储出了问题呢?如果,能重现这次的性能问题该多好啊,只是没有如果!

     

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值