技术开发 频道

Oracle性能优化之诊断latch竞争

  【IT168 技术文档】 

 

  •  Oracle性能优化:数据库配置和IO问题
  •  Oracle性能优化经验分享之系统参数设置
           Oracle性能优化之优化排序操作

           1、概念

     

      Latch是简单的、低层次的序列化技术,用以保护SGA中的共享数据结构,比如并发用户列表和buffer cache里的blocks信息。一个服务器进程或后台进程在开始操作或寻找一个共享数据结构之前必须获得对应的latch,在完成以后释放latch。不必对latch本身进行优化,如果latch存在竞争,表明SGA的一部分正在经历不正常的资源使用。

      1)Latch的作用:

      A、序列化访问:保护SGA中的共享数据结构;保护共享内存的分配。

      B、序列化执行:避免同时执行某些关键代码;避免互相干扰。

      2)Latch请求的两种类型:

      A、willing-to-wait:请求的进程经过短时间的等待后再次发出请求,直到获得latch

      B、immediate:如果没有获得latch,请求的进程不等待,而是继续处理其他指令。

      2、检查Latch竞争

      检查latch free是不是主要的wait event:

      Select * from v$system_event order by time_waited;

      检查latch的使用情况:

      Select * from v$latch:

      与willing-to-wait请求有关的列:gets、misses、sleeps、wait_time、cwait_time、spin_gets

      与immediate请求有关的列:immediate_gets、immediate_misses

      Gets: number of successful willing-to-wait requests for a latch;

      Misses: number of times an initial wiling-to-wait request was unsuccessful;

      Sleeps: number of times a process waited after an initial willing-to-wait request;

      Wait_time: number of milliseconds waited after willing-to-wait request;

      Cwait_time: a measure of the cumulative wait time including the time spent spinning and sleeping,the overhead of context switches due to OS time slicing and page faults and interrupts;

      Spin_gets: gets that misses first try but succeed after spinning.

      Immediate_gets: number of successful immediate requests for each latch;

      Immediate_misss: number of unsuccessful immediate requests for each latch;

      一般无需调整latch,但是下列的措施是有用的:

      A、对处于竞争中的latch做进一步的调查

      B、如果竞争主要存在于shared pool和library cache中,可以考虑调整应用

      C、如果进一步的调查显示需要调整shared pool和buffer cache,就进行调整

      Select * from v$latch where name like ‘%shared pool%’ or name like ‘%library cache%’;

      如果竞争是在shared pool或library cache上,表示下列集中情况:

      A、不能共享的sql,应检查他们是否相似,考虑以变量代替sql中的常量:

      Select sql_text from v$sqlarea where executions=1 order by upper(sql_text);

      B、共享sql被重新编译,考虑library cache的大小是否需要调整:

      SELECT sql_text,parse_calls,executions FROM v$sqlarea where parse_calls>5;

      C、library cache不够大。

  •  

    0
    相关文章