天天看點

[MySQL 5.6] Performance Schema 表類型縱覽 (3)1.SETUP table配置表2.CURRENT EVENT table3.HISTORY table4.SUMMARY table5.INSTANCE table6.其他雜項表

前面已經提到過了部分performance schema表,這裡再總結下,ps庫下主要分為幾類表

<code></code>

該表列出了目前線程正在等待的事件,主要包括以下幾列:

thread_id:線程id

event_id:目前線程的事件id,和thread_id組成一個primary key.

end_event_id:當事件開始時,這一列被設定為null。當事件結束時,再更新為目前的事件id

event_name:産生該事件的instrument名

source:該事件産生時的源碼檔案;例如如果在等待一個mutex,檢視對應的源碼,就可以知道在那裡被阻塞住。

<code>timer_start</code>, <code>timer_end</code>, <code>timer_wait:事件開始/結束和等待的時間,機關為皮秒(</code>picoseconds)

spins:互斥鎖或讀寫鎖spin的次數<code></code>

<code>object_schema</code>, <code>object_name</code>, <code>object_type</code>, <code>object_instance_begin:這幾列的值取決于不同的對象類型</code>

<code>     a.對于</code><code>cond</code>, <code>mutex</code>, <code>rwlock類型,</code><code>object_schema</code>, <code>object_name</code>, 以及 <code>object_type</code> 的值為<code>null</code>.object_instance_begin表示該同步對象建立的記憶體位址

     b.對于檔案io對象,object_schema為null,object_name為檔案名,object_type為file,object_instance_begin是記憶體位址。

     c.對于socket對象,object_name為該socket的ip:sock值,object_instance_begin是對象記憶體位址

     d.對于表i/o對象,object_schema是表的schema名,object_name是表名,object_type為table或者temporary table,object_instance_begin是對象的記憶體位址

index:使用到的索引名

nesting_event_id:該事件鎖嵌套在的事件id,

nesting_event_type:嵌套事件類型(statement, stage, wait)

operation:操作類型(lock, read, write)

number_of_bytes:該操作讀或寫的比特數,對于表的i/o對象,number_of_bytes值為null

flags:預留列

stage表中列出了一條sql執行的過程,例如解析sql,打開一個表,或者執行一次filesort操作等等,可以與show processlist結合起來。該表每一行顯示了該線程最近的一條記錄

主要包括以下幾列:

thread_id:線程id

event_id:事件id

end_event_id:剛結束的事件id,以上三列的含義和wait表的相同

source:源碼位置

<code>timer_start</code>, <code>timer_end</code>, <code>timer_wait:本階段開始、結束以及持續的時間;如果事件沒有結束,</code>timer_end和timer_wait值為null;如果該事件對應的instrument的timed列設定為no(setup_instruments),這三列的值都為null

nesting_event_id:目前事件被嵌套的事件id,一個stage事件的嵌套事件通常是一個statement事件

nesting_event_type:嵌套事件類型(statement, stage 或者wait)

對statement的監控從發現一個線程活躍開始,到線程的活躍行為結束。換句話說,是從伺服器接受用戶端的第一個通信包開始,到伺服器發送完所有的響應,監控隻發生在最頂層的語句,對于在語句中包含的存儲過程或者子查詢不會單獨列出。

從用戶端發出的一個請求,既可以是一個command,也可以是一條sql,通過statement/com 和statement/sql來劃分,再往下劃分就是具體的sql類型或者command。

另外還有一些錯誤處理的instrument:

statement/com/error:用于處理伺服器不能了解的command

statement/sql/error:用于處理無法解析的sql。

在剛開始伺服器接受到一條sql時,先将看做statement/com/query,在完成解析後,再将其設定成statement/sql/*

該表的列比較多,主要包括:

thread_id、event_id、end_event_id、event_name、source:和上面介紹的兩個表含義類似,這裡不再贅述

lock_time:等待表鎖的時間

sql_text:sql語句,對于command,值為null

digest:該sql格式化後的 md5值,需要statement_digest打開才生效

digest_text:該sql格式化後的字元串,需要statement_digest打開才生效

current_schema:該sql的預設連結的資料庫

<code>object_schema</code>, <code>object_name</code>, <code>object_type:保留列,值為null</code>

object_instance_begin:用于标示該對象在記憶體中的位址<code></code>

mysql_errno:該sql産生的錯誤号

returned_sqlstate:sqlstate值

message_text:錯誤資訊

errors:是否發生錯誤,如果sqlstate值以00(完成) 或者01(警告)開始,值為0;否則為1

warnings:告警次數,以上列都取自該sql的diagnostics area

rows_affected:該sql影響的行數

rows_sent:發送到用戶端的行數

rows_examined:在sql執行過程中從存儲引擎讀取的記錄數

created_tmp_disk_tables、created_tmp_tables、select_full_join、select_full_range_join、select_range、select_range_check、select_scan、sort_merge_passes、sort_range、sort_rows、sort_scan:這些列的名字也有對應的status變量,含義相同,但這裡隻針對目前這個sql的統計。

no_index_used:如果sql執行了一次全表掃描,沒有用到索引的話值為1,否則為0

<code>nesting_event_id</code>, <code>nesting_event_type:保留列,目前值為null</code>

<code>history/history long表跟cureent 表結構類似,隻是存儲的資料量不同,這裡不再贅述。</code>

<code>彙總表,對事件資訊進行聚集。</code>

<code>彙總表是我們關注的重點,因為它省略了人工處理資料的過程,由伺服器來進行資料聚集。</code>

<code>主要包括以下幾種:</code>

這三個表分别根據event名/instance(event_name、object_instance_begin)以及(thread_id,event_name)進行聚合,聚合列包括:

count_star:事件計數

sum_timer_wait:總的等待時間

min_timer_wait:最小等待時間

avg_timer_wait:平均等待時間

同樣包含<code>count_star</code>, <code>sum_timer_wait</code>, <code>min_timer_wait</code>, <code>avg_timer_wait</code>, <code>max_timer_wait</code>

除了<code>count_star</code>, <code>sum_timer_wait</code>, <code>min_timer_wait</code>, <code>avg_timer_wait</code>, <code>max_timer_wait,還包括:</code>

sum_<code>xxx:一些狀态資訊的sum值,例如</code><code>sum_lock_time、sum_errors等等</code>

<code>first_seen_timestamp</code>, <code>last_seen_timestamp,該sql的摘要(digest)資訊第一次生成,以及最近一次生成的時間戳。</code><code></code>

聚合的sql在digest表中生成的規則:

a.存在對應的格式化的sql,将其資訊聚合到該記錄中,更新last_seen_timestamp

b.新的記錄加入到表中(表未滿),first_seen_timestamp和last_seen_timestamp更新為目前時間

internal lock通過sql層函數thr_lock調用,顯示在operation這一列,有如下值:

read normal 

read with shared locks 

read high priority 

read no insert 

write allow write 

write concurrent insert 

write delayed 

write low priority 

write normal

external lock則通過接口函數handler::external_lock調用存儲引擎層,operation列的值為:

read external

write external

<code>執行個體表記錄了目前被監控的事件狀态,主要包括以下幾種:</code>

列出目前正在運作的condition wait對象,隻包含兩列:

name:正在等待的instrument名

object_instance_begin: 該condition被監控時的記憶體位址

當執行file io instrument時的檔案資訊,當一個檔案從未被打開時,不會在其中顯示,如果從磁盤上删除了檔案,也會從該表中删除。

包含3列:

name:檔案名

event_name:instrument名

open_count:目前檔案打開的次數;如果一個檔案先打開,再關閉了,這個檔案的open_count值為0.

列出了所有目前等待的互斥量,該表包含三列:

name:該mutex的命名

object_instance_begin:對象執行個體的記憶體位址

locked_by_thread_id:目前鎖住該互斥量的線程id

對于每一個mutex instrument,ps提供了以下資訊:

d.當一個線程成功鎖住一個mutex,會

e.當該mutex被釋放時,locked_by_thread_id列被設定為null

通過在以下兩個表上執行查詢,可以有助于發現性能瓶頸:

name: 該讀寫鎖instrument命名

object_instance_begin:被建立時的記憶體位址

write_locked_by_thread_id:目前持有寫鎖的線程id

read_locked_by_count:讀鎖計數器

記錄目前所有的實時socket連接配接對象。主要包括兩種監聽socket(server_tcpip_socket或者server_unix_socket)以及一種用戶端連接配接(client_connection),當一個使用者線程中斷,對應的記錄被删除。

該表主要包含以下幾列:

event_name:命名為 <code>wait/io/socket/*</code>

object_instance_begin:該對象的記憶體位址<code></code>

socket_id: 内部socket id

ip:用戶端ip位址

port:用戶端端口号

state:使用者線程狀态,idle或者active

用戶端連接配接資訊表

相對而言,這些雜項表不是我們性能調優的重點,有興趣的可以自行閱讀文檔