首頁 資料庫 mysql教程 latch:cachebufferschains等待事件导致的latch争用的原理原因与

latch:cachebufferschains等待事件导致的latch争用的原理原因与

Jun 07, 2016 pm 03:22 PM
latch 事件 等待

latch:cache buffers chains 原理 当一个数据块读入到sga中时,该块的块头(buffer header)会放置在一个hash bucket的链表(hash chain)中。该内存结构由一系列cache buffers chains子latch保护(又名hash latch或者cbc latch)。对Buffer cache中的块,要sele

latch:cache buffers chains 原理

当一个数据块读入到sga中时,该块的块头(buffer header)会放置在一个hash bucket的链表(hash chain)中。该内存结构由一系列cache buffers chains子latch保护(又名hash latch或者cbc latch)。对Buffer cache中的块,要select或者update、insert,delete等,都得先获得cache buffers chains子latch,以保证对chain的排他访问。若在过程中发生争用,就会等待latch:cache buffers chains事件。

产生原因: 1. 低效率的SQL语句(主要体现在逻辑读过高) 在某些环境中,应用程序打开执行相同的低效率SQL语句的多个并发会话,这些SQL语句都设法得到相同的数据集,每次执行都带有高 BUFFER_GETS(逻辑读取)的SQL语句是主要的原因。相反,较小的逻辑读意味着较少的latch get操作,从而减少锁存器争用并改善性能。注意v$sql中BUFFER_GETS/EXECUTIONS大的语句。 2.Hot block 当多个会话重复访问一个或多个由同一个子cache buffers chains锁存器保护的块时,热块就会产生。当多个会话争用cache buffers chains子锁存器时,就会出现这个等待事件。有时就算调优了SQL,但多个会话同时执行此SQL,那怕只是扫描特定少数块,也是也会出现HOT BLOCK的。

检查看下当前active的会话中产生的比较高buffer get的SQL: select * from (select sql_text,hash_value,buffer_gets/executions from v$sql where executions0 and hash_value in (select sql_hash_value from gv$session where statu
s='ACTIVE' )order by buffer_gets/executions desc ) where rownum

通过v$latch查看自实例启动以来cache buffers chains锁存器争用是否厉害: select round((misses/gets)*100)||'%',round(100*(immediate_misses/(immediate_gets+immediate_misses)))||' %' from v$latch where name='cache buffers chains'; 对于willing-to-wait,比较重要的是misses/gets,假如大于1%就应该发生争用了,大于10%,就有争用严重的情况了。对于no-wait模式,immediate_misses/(immediate_gets+immediate_misses)也一样。

通过查询子锁存器视图,看看是否有Hot Block,并且获取有Hot Block的子锁存器addr select * from (select addr,child#,gets,misses,sleeps from v$latch_children where name='cache buffers chains' order by sleeps desc ) where rownum

另外一种判断Hot block方法,是从当前等待latch:cache buffers chains事件的会话出发。通过v$session_wait视图,获得P1RAW即子锁存器的地址。通过重复观察v$session_wait视图,发现某个子锁存器地址较多地出现,那么该子锁存器管辖的chain可能有热块。 select p1,p1raw from v$session_wait where event='latch: cache buffers chains';

所以v$session的p1raw与x$bh的laddr,以及v$latch_children的addr是同样的东西,都是子锁存器的地址。大概思路是,通过子锁存器的热度来找到所管辖的对象,以及对象的热度。

通过子锁存器地址,即v$latch_children的addr字段,来获取这些子锁存器所管理的对象的文件号块号与热度。 注意到x$bh字典表中的tch字段表示的就是block的touch count,一般来说这个值越高那么这个块就越热,我们称这样的块就叫做热点块。 select hladdr,obj,(select object_name from dba_objects where (data_object_id is null and object_id=x.obj) or data_object_id=x.obj and rownum=1) as object_name,dbarfil,dbablk,tch from x$bh x where hladdr in ('00000000DA253C08','00000000DA380310') order by tch desc;
根据FILE#,dbablk来找出对应对象。 select * from dba_extents where file_id=10 and 36643122 between block_id and block_id + blocks - 1;

直接通过v$bh视图直接查找数据库热点块,从而找到热点的对象。 select * from (select hladdr,ts#,file#,dbarfil,dbablk,tch from x$bh order by tch desc) where rownum 0 GROUP BY O.OWNER, O.OBJECT_NAME, O.OBJECT_TYPE ORDER BY SUM(TCH) DESC) WHERE ROWNUM

查看引起latch: cache buffers chains的sql select * from (select count(*),sql_id,nvl(o.object_name,ash.current_obj#) objn,substr(o.object_type,0,10) otype, CURRENT_FILE# fn,CURRENT_BLOCK# blockn from v$active_session_history ash,all_objects o where event like 'latch: cache buffers chains' and o.object_id (+)= ash.CURRENT_OBJ# group by sql_id, current_obj#, current_file#, current_block#, o.object_name,o.object_type order by count(*) desc )where rownum select sql_fulltext from v$sqlarea where sql_id='&sqlid';

解决方法 1.优化SQL,如优化nested loop join,如果有可能使用hash join代替nested loop join。 2.可以利用对热块索引进行hash分区,或者使用hash簇的方式减缓热块现象。 3.调整表的pctfree值,将数据尽可能的分布到多个块中,但相同的查询要扫更多块,有负面作用。 4.并行查询是直接读数据文件,不经过SGA,即direct path read,所以就不存在锁存器争用的情况了。但其一般是为了大量数据读取而使用的,不作为一般的解决方案。 5.等问题自己消失。有时当出现latch争用时,故障时刻确实没有较好的方式解决,找到病因才是关键。

附录:查看cache buffers chains有多少个子锁存器 Select count(*) from v$latch_children where name = 'cache buffers chains';
找出前10的热点块对象: select /*+rule*/ owner,object_name from dba_objects where data_object_id in (select obj from (select obj from x$bh order by tch desc) where rownum Oracle11g联机文档中摘录: The cache buffers chains latches are used to protect a buffer list in the buffer cache. These latches are used when searching for, adding, or removing a buffer from the buffer cache. Contention on this latch usually means that there is a block that is greatly contended for (known as a hot block). To identify the heavily accessed buffer chain, and hence the contended for block, look at latch statistics for the cache buffers chains latches using the view V$LATCH_CHILDREN. If there is a specific cache buffers chains child latch that has many more GETS, MISSES, and SLEEPS when compared with the other child latches, then this is the contended for child latch. This latch has a memory address, identified by the ADDR column. Use the value in the ADDR column joined with the X$BH table to identify the blocks protected by this latch. For example, given the address (V$LATCH_CHILDREN.ADDR) of a heavily contended latch, this queries the file and block numbers: SELECT OBJ data_object_id, FILE#, DBABLK,CLASS, STATE, TCH FROM X$BH WHERE HLADDR = 'address of latch' ORDER BY TCH; X$BH.TCH is a touch count for the buffer. A high value for X$BH.TCH indicates a hot block. Many blocks are protected by each latch. One of these buffers will probably be the hot block. Any block with a high TCH value is a potential hot block. Perform this query several times, and identify the block that consistently appears in the output. After you have identified the hot block, query DBA_EXTENTS using the file number and block number, to identify the segment. After you have identified the hot block, you can identify the segment it belongs to with the following query: SELECT OBJECT_NAME, SUBOBJECT_NAME FROM DBA_OBJECTS WHERE DATA_OBJECT_ID = &obj; In the query, &obj is the value of the OBJ column in the previous query on X$BH.
Latch: cache buffers chains Description: Blocks in the buffer cache are placed on linked lists (cache buffer chains) which hang off a hash table. The hash chain that a block is placed on is based on the DBA and CLASS of the block. Each hash chain is protected by a single child latch. Processes need to get the relevant latch to allow them the scan a hash chain for a buffer so that the linked list does not change underneath them. Contention: Contention for these latches can be caused by: - Very long buffer chains. There is a known problem that can result in long buffer chains - - very very heavy access to a single block. This would require the application to be reviewed. - To identify the heavily accessed buffer chain look at the latch stats for this latch under and match this to .

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

PHP非同步發送郵件:避免長時間等待郵件發送完成。 PHP非同步發送郵件:避免長時間等待郵件發送完成。 Sep 19, 2023 am 09:10 AM

PHP非同步發送郵件:避免長時間等待郵件發送完成。導言:在Web開發中,發送郵件是常見的功能之一。但是,由於郵件發送需要與伺服器進行通信,往往會導致用戶在等待郵件發送完成的過程中出現長時間的等待。為了解決這個問題,我們可以使用PHP非同步發送郵件的方式來優化使用者體驗。本文將介紹如何透過具體的程式碼範例實現PHP非同步發送郵件,並避免長時間的等待。一、理解異步發送郵件

事件 ID 4660:已刪除物件 [修復] 事件 ID 4660:已刪除物件 [修復] Jul 03, 2023 am 08:13 AM

我們的一些讀者遇到了事件ID4660。他們通常不確定該怎麼做,所以我們在本指南中解釋。刪除物件時通常會記錄事件ID4660,因此我們還將探索一些實用的方法在您的電腦上修復它。什麼是事件ID4660?事件ID4660與活動目錄中的物件相關,將由下列任一因素觸發:物件刪除–每當從ActiveDirectory中刪除物件時,都會記錄事件ID為4660的安全事件。手動變更–當使用者或管理員手動變更物件的權限時,可能會產生事件ID4660。變更權限設定、修改存取等級或新增或刪除人員或群組時,可能會發生這種情

在iPhone鎖定畫面上取得即將到來的日曆事件 在iPhone鎖定畫面上取得即將到來的日曆事件 Dec 01, 2023 pm 02:21 PM

在運行iOS16或更高版本的iPhone上,您可以直接在鎖定畫面上顯示即將到來的日曆事件。繼續閱讀以了解它是如何完成的。由於錶盤複雜功能,許多AppleWatch用戶習慣能夠看一眼手腕來查看下一個即將到來的日曆事件。隨著iOS16和鎖定螢幕小部件的出現,您可以直接在iPhone上查看相同的日曆事件訊息,甚至無需解鎖設備。日曆鎖定螢幕小元件有兩種風格,可讓您追蹤下一個即將發生的事件的時間,或使用更大的小元件來顯示事件名稱及其時間。若要開始新增小元件,請使用面容ID或觸控ID解鎖iPhone,長按

在JavaScript中,'oninput'事件的用途是什麼? 在JavaScript中,'oninput'事件的用途是什麼? Aug 26, 2023 pm 03:17 PM

當輸入框中新增值時,就會發生oninput事件。您可以嘗試執行以下程式碼來了解如何在JavaScript中實現oninput事件-範例<!DOCTYPEhtml><html>  <body>   <p>Writebelow:</p>   <inputtype="text&quot

jQuery中如何實作select元素的改變事件綁定 jQuery中如何實作select元素的改變事件綁定 Feb 23, 2024 pm 01:12 PM

jQuery是一個受歡迎的JavaScript函式庫,可以用來簡化DOM操作、事件處理、動畫效果等。在web開發中,常常會遇到需要對select元素進行改變事件綁定的情況。本文將介紹如何使用jQuery實作對select元素改變事件的綁定,並提供具體的程式碼範例。首先,我們需要使用標籤來建立一個包含選項的下拉式選單:

jquery中常用的事件有哪些 jquery中常用的事件有哪些 Jan 03, 2023 pm 06:13 PM

jquery中常用的事件有:1、window事件;2、滑鼠事件,是當使用者在文件上方移動或點選滑鼠時而產生的事件,包括滑鼠點選、移入事件、移出事件等;3、鍵盤事件,是使用者每次按下或釋放鍵盤上的按鍵時都會產生事件,包括按下按鍵事件、釋放按鍵按鍵等;4、表單事件,例如當元素獲得焦點時會觸發focus()事件,失去焦點時會觸發blur()事件,表單提交時會觸發submit()事件。

如何在PHP專案中實現日曆功能和事件提醒? 如何在PHP專案中實現日曆功能和事件提醒? Nov 02, 2023 pm 12:48 PM

如何在PHP專案中實現日曆功能和事件提醒?在開發Web應用程式時,行事曆功能和事件提醒是常見的需求之一。無論是個人日程管理、團隊協作,或是線上活動安排,行事曆功能都可以提供便利的時間管理和事務安排。在PHP專案中實現日曆功能和事件提醒可以透過以下步驟來完成。資料庫設計首先,需要設計資料庫表來儲存日曆事件的相關資訊。一個簡單的設計可以包含以下欄位:id:事件的唯一

深入研究jQuery中的關閉按鈕事件 深入研究jQuery中的關閉按鈕事件 Feb 24, 2024 pm 05:09 PM

深入理解jQuery中的關閉按鈕事件在前端開發過程中,經常會遇到需要實現關閉按鈕功能的情況,例如關閉彈跳窗、關閉提示框等。而在使用jQuery這個流行的JavaScript函式庫時,實作關閉按鈕事件也變得異常簡單又方便。本文將深入探討如何利用jQuery來實現關閉按鈕事件,並提供具體的程式碼範例,幫助讀者更好地理解和掌握這個技術。首先,我們需要了解在HTML中如何定

See all articles