真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

怎么理解MySQL5.6中的PERFORMANCE_SCHEM

本篇內(nèi)容介紹了“怎么理解MySQL5.6中的PERFORMANCE_SCHEM”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

創(chuàng)新互聯(lián)建站云計(jì)算的互聯(lián)網(wǎng)服務(wù)提供商,擁有超過13年的服務(wù)器租用、四川聯(lián)通機(jī)房服務(wù)器托管、云服務(wù)器、虛擬空間、網(wǎng)站系統(tǒng)開發(fā)經(jīng)驗(yàn),已先后獲得國(guó)家工業(yè)和信息化部頒發(fā)的互聯(lián)網(wǎng)數(shù)據(jù)中心業(yè)務(wù)許可證。專業(yè)提供云主機(jī)、虛擬空間、國(guó)際域名空間、VPS主機(jī)、云服務(wù)器、香港云服務(wù)器、免備案服務(wù)器等。

通過sql語句找到在經(jīng)歷什么等待事件!

Statement -> stage -> wait的三級(jí)結(jié)構(gòu),通過nesting_event_id進(jìn)行關(guān)聯(lián),它表示某個(gè)事件的父event_id。

比如分析包含count(*)的某條SQL語句,具體如下:(類似于oracle的v$sql, v$sqlstat, v$sqlarea)

SELECT

EVENT_ID,

sql_text

FROM events_statements_history

WHERE sql_text LIKE '%count(*)%';

+----------+--------------------------------------+

| EVENT_ID | sql_text |

+----------+--------------------------------------+

| 1690 | select count(*) from chuck.test_slow |

+----------+--------------------------------------+

a.查看每個(gè)階段的時(shí)間消耗:(類似于oracle的時(shí)間模型V$SYS_TIME_MODEL  V$SESS_TIME_MODEL)

SELECT

event_id,

EVENT_NAME,

SOURCE,

TIMER_END - TIMER_START

FROM events_stages_history_long

WHERE NESTING_EVENT_ID = 1690;

+----------+--------------------------------+----------------------+-----------------------+

| event_id | EVENT_NAME | SOURCE | TIMER_END-TIMER_START |

+----------+--------------------------------+----------------------+-----------------------+

……

| 2647 | stage/sql/Sending data | sql_executor.cc:192 | 7369072089000 |

b.查看某個(gè)階段的鎖等待情況 (類似于oracle的v$session_wait)

針對(duì)每個(gè)stage可能出現(xiàn)的鎖等待,一個(gè)stage會(huì)對(duì)應(yīng)一個(gè)或多個(gè)wait,events_waits_history_long這個(gè)表容易爆滿[默認(rèn)閥值10000]。由于select count(*)需要IO(邏輯IO或者物理IO),所以在stage/sql/Sending data階段會(huì)有io等待的統(tǒng)計(jì)。通過stage_xxx表的event_id字段與waits_xxx表的nesting_event_id進(jìn)行關(guān)聯(lián)。

SELECT

event_id,

event_name,

source,

timer_wait,

object_name,

index_name,

operation,

nesting_event_id

FROM events_waits_history_long

WHERE nesting_event_id = 2647;

+----------+---------------------------+-----------------+------------+-------------+------------+-----------+------------------+

| event_id | event_name | source | timer_wait | object_name | index_name | operation | nesting_event_id |

+----------+---------------------------+-----------------+------------+-------------+------------+-----------+------------------+

| 190607 | wait/io/table/sql/handler | handler.cc:2842 | 1845888 | test_slow | idx_c1 | fetch | 2647 |

 

https://www.cnblogs.com/zhoujinyi/p/5236705.html

MySQL5.6 PERFORMANCE_SCHEMA 說明

背景:

      MySQL 5.5開始新增一個(gè)數(shù)據(jù)庫:PERFORMANCE_SCHEMA,主要用于收集數(shù)據(jù)庫服務(wù)器性能參數(shù)。并且?guī)炖锉淼拇鎯?chǔ)引擎均為PERFORMANCE_SCHEMA,而用戶是不能創(chuàng)建存儲(chǔ)引擎為PERFORMANCE_SCHEMA的表。MySQL5.5默認(rèn)是關(guān)閉的,需要手動(dòng)開啟,在配置文件里添加:

[mysqld]

performance_schema=ON

查看是否開啟:

mysql>show variables like 'performance_schema';

+--------------------+-------+

| Variable_name      | Value |

+--------------------+-------+

| performance_schema | ON    |

+--------------------+-------+

從MySQL5.6開始,默認(rèn)打開,本文就從MySQL5.6來說明,在數(shù)據(jù)庫使用當(dāng)中PERFORMANCE_SCHEMA的一些比較常用的功能。具體的信息可以查看官方文檔。

相關(guān)表信息:

一:配置(setup)表:

zjy@performance_schema 10:16:56>show tables like '%setup%';

+----------------------------------------+

| Tables_in_performance_schema (%setup%) |

+----------------------------------------+

| setup_actors                           |

| setup_consumers                        |

| setup_instruments                      |

| setup_objects                          |

| setup_timers                           |

+----------------------------------------+

1,setup_actors:配置用戶緯度的監(jiān)控,默認(rèn)監(jiān)控所有用戶。

zjy@performance_schema 10:19:11>select * from setup_actors;

+------+------+------+

| HOST | USER | ROLE |

+------+------+------+

| %    | %    | %    |

+------+------+------+

2,setup_consumers:配置events的消費(fèi)者類型,即收集的events寫入到哪些統(tǒng)計(jì)表中。

zjy@: performance_schema 10:23:35>select * from setup_consumers;

+--------------------------------+---------+

| NAME                           | ENABLED |

+--------------------------------+---------+

| events_stages_current          | NO      |

| events_stages_history          | NO      |

| events_stages_history_long     | NO      |

| events_statements_current      | YES     |

| events_statements_history      | NO      |

| events_statements_history_long | NO      |

| events_waits_current           | NO      |

| events_waits_history           | NO      |

| events_waits_history_long      | NO      |

| global_instrumentation         | YES     |

| thread_instrumentation         | YES     |

| statements_digest              | YES     |

+--------------------------------+---------+

這里需要說明的是需要查看哪個(gè)就更新其ENABLED列為YES。如:

zjy@performance_schema 10:25:02>update setup_consumers set ENABLED='YES' where NAME in ('events_stages_current','events_waits_current');

Query OK, 2 rows affected (0.00 sec)

更新完后立即生效,但是服務(wù)器重啟之后又會(huì)變回默認(rèn)值,要永久生效需要在配置文件里添加:

[mysqld]

#performance_schema

performance_schema_consumer_events_waits_current=on

performance_schema_consumer_events_stages_current=on

performance_schema_consumer_events_statements_current=on

performance_schema_consumer_events_waits_history=on

performance_schema_consumer_events_stages_history=on

performance_schema_consumer_events_statements_history=on

即在這些表的前面加上:performance_schema_consumer_xxx。表setup_consumers里面的值有個(gè)層級(jí)關(guān)系:

global_instrumentation > thread_instrumentation = statements_digest > events_stages_current = events_statements_current = events_waits_current > events_stages_history = events_statements_history = events_waits_history > events_stages_history_long = events_statements_history_long = events_waits_history_long

只有上一層次的為YES,才會(huì)繼續(xù)檢查該本層為YES or NO。global_instrumentation是最高級(jí)別consumer,如果它設(shè)置為NO,則所有的consumer都會(huì)忽略。其中history和history_long存的是current表的歷史記錄條數(shù),history表記錄了每個(gè)線程最近等待的10個(gè)事件,而history_long表則記錄了最近所有線程產(chǎn)生的10000個(gè)事件,這里的10和10000都是可以配置的。這三個(gè)表表結(jié)構(gòu)相同,history和history_long表數(shù)據(jù)都來源于current表。長(zhǎng)度通過控制參數(shù):

zjy@performance_schema 11:10:03>show variables like 'performance_schema%history%size';

+--------------------------------------------------------+-------+

| Variable_name                                          | Value |

+--------------------------------------------------------+-------+

| performance_schema_events_stages_history_long_size     | 10000 |

| performance_schema_events_stages_history_size          | 10    |

| performance_schema_events_statements_history_long_size | 10000 |

| performance_schema_events_statements_history_size      | 10    |

| performance_schema_events_waits_history_long_size      | 10000 |

| performance_schema_events_waits_history_size           | 10    |

+--------------------------------------------------------+-------+

3,setup_instruments:配置具體的instrument,主要包含4大類:idle、stage/xxx、statement/xxx、wait/xxx:

zjy@performance_schema 10:56:35>select name,count(*) from setup_instruments group by LEFT(name,5);

+---------------------------------+----------+

| name                            | count(*) |

+---------------------------------+----------+

| idle                            |        1 |

| stage/sql/After create          |      111 |

| statement/sql/select            |      179 |

| wait/synch/mutex/sql/PAGE::lock |      296 |

+---------------------------------+----------+

idle表示socket空閑的時(shí)間,stage類表示語句的每個(gè)執(zhí)行階段的統(tǒng)計(jì),statement類統(tǒng)計(jì)語句維度的信息,wait類統(tǒng)計(jì)各種等待事件,比如IO,mutux,spin_lock,condition等。

4,setup_objects:配置監(jiān)控對(duì)象,默認(rèn)對(duì)mysql,performance_schema和information_schema中的表都不監(jiān)控,而其它DB的所有表都監(jiān)控。

zjy@performance_schema 11:00:18>select * from setup_objects;

+-------------+--------------------+-------------+---------+-------+

| OBJECT_TYPE | OBJECT_SCHEMA      | OBJECT_NAME | ENABLED | TIMED |

+-------------+--------------------+-------------+---------+-------+

| TABLE       | mysql              | %           | NO      | NO    |

| TABLE       | performance_schema | %           | NO      | NO    |

| TABLE       | information_schema | %           | NO      | NO    |

| TABLE       | %                  | %           | YES     | YES   |

+-------------+--------------------+-------------+---------+-------+

5,setup_timers:配置每種類型指令的統(tǒng)計(jì)時(shí)間單位。MICROSECOND表示統(tǒng)計(jì)單位是微妙,CYCLE表示統(tǒng)計(jì)單位是時(shí)鐘周期,時(shí)間度量與CPU的主頻有關(guān),NANOSECOND表示統(tǒng)計(jì)單位是納秒。但無論采用哪種度量單位,最終統(tǒng)計(jì)表中統(tǒng)計(jì)的時(shí)間都會(huì)裝換到皮秒。(1秒=1000000000000皮秒)

zjy@performance_schema 11:05:12>select * from setup_timers;

+-----------+-------------+

| NAME      | TIMER_NAME  |

+-----------+-------------+

| idle      | MICROSECOND |

| wait      | CYCLE       |

| stage     | NANOSECOND  |

| statement | NANOSECOND  |

+-----------+-------------+

二:instance表

1,cond_instances:條件等待對(duì)象實(shí)例

表中記錄了系統(tǒng)中使用的條件變量的對(duì)象,OBJECT_INSTANCE_BEGIN為對(duì)象的內(nèi)存地址。

2,file_instances:文件實(shí)例

表中記錄了系統(tǒng)中打開了文件的對(duì)象,包括ibdata文件,redo文件,binlog文件,用戶的表文件等,open_count顯示當(dāng)前文件打開的數(shù)目,如果重來沒有打開過,不會(huì)出現(xiàn)在表中。

zjy@performance_schema 11:20:04>select * from file_instances limit 2,5;

+---------------------------------+--------------------------------------+------------+

| FILE_NAME                       | EVENT_NAME                           | OPEN_COUNT |

+---------------------------------+--------------------------------------+------------+

| /var/lib/mysql/mysql/plugin.frm | wait/io/file/sql/FRM                 |          |

| /var/lib/mysql/mysql/plugin.MYI | wait/io/file/myisam/kfile            |          1 |

| /var/lib/mysql/mysql/plugin.MYD | wait/io/file/myisam/dfile            |          1 |

| /var/lib/mysql/ibdata1          | wait/io/file/innodb/innodb_data_file |          2 |

| /var/lib/mysql/ib_logfile0      | wait/io/file/innodb/innodb_log_file  |          2 |

+---------------------------------+--------------------------------------+------------+

3,mutex_instances:互斥同步對(duì)象實(shí)例

表中記錄了系統(tǒng)中使用互斥量對(duì)象的所有記錄,其中name為:wait/synch/mutex/*。LOCKED_BY_THREAD_ID顯示哪個(gè)線程正持有mutex,若沒有線程持有,則為NULL。

4,rwlock_instances: 讀寫鎖同步對(duì)象實(shí)例

表中記錄了系統(tǒng)中使用讀寫鎖對(duì)象的所有記錄,其中name為 wait/synch/rwlock/*。WRITE_LOCKED_BY_THREAD_ID為正在持有該對(duì)象的thread_id,若沒有線程持有,則為NULL。READ_LOCKED_BY_COUNT為記錄了同時(shí)有多少個(gè)讀者持有讀鎖。(通過 events_waits_current 表可以知道,哪個(gè)線程在等待鎖;通過rwlock_instances知道哪個(gè)線程持有鎖。rwlock_instances的缺陷是,只能記錄持有寫鎖的線程,對(duì)于讀鎖則無能為力)。

5,socket_instances:活躍會(huì)話對(duì)象實(shí)例
表中記錄了thread_id,socket_id,ip和port,其它表可以通過thread_id與socket_instance進(jìn)行關(guān)聯(lián),獲取IP-PORT信息,能夠與應(yīng)用對(duì)接起來。
event_name主要包含3類:
wait/io/socket/sql/server_unix_socket,服務(wù)端unix監(jiān)聽socket
wait/io/socket/sql/server_tcpip_socket,服務(wù)端tcp監(jiān)聽socket
wait/io/socket/sql/client_connection,客戶端socket

三:Wait表

1,events_waits_current:記錄了當(dāng)前線程等待的事件

2,events_waits_history:記錄了每個(gè)線程最近等待的10個(gè)事件

3,events_waits_history_long:記錄了最近所有線程產(chǎn)生的10000個(gè)事件

表結(jié)構(gòu)定義如下:

CREATE TABLE `events_waits_current` (

  `THREAD_ID` bigint(20) unsigned NOT NULL COMMENT '線程ID',

  `EVENT_ID` bigint(20) unsigned NOT NULL COMMENT '當(dāng)前線程的事件ID,和THREAD_ID確定唯一',

  `END_EVENT_ID` bigint(20) unsigned DEFAULT NULL COMMENT '當(dāng)事件開始時(shí),這一列被設(shè)置為NULL。當(dāng)事件結(jié)束時(shí),再更新為當(dāng)前的事件ID',

  `EVENT_NAME` varchar(128) NOT NULL COMMENT '事件名稱',

  `SOURCE` varchar(64) DEFAULT NULL COMMENT '該事件產(chǎn)生時(shí)的源碼文件',

  `TIMER_START` bigint(20) unsigned DEFAULT NULL COMMENT '事件開始時(shí)間(皮秒)',

  `TIMER_END` bigint(20) unsigned DEFAULT NULL COMMENT '事件結(jié)束結(jié)束時(shí)間(皮秒)',

  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL COMMENT '事件等待時(shí)間(皮秒)',

  `SPINS` int(10) unsigned DEFAULT NULL COMMENT '',

  `OBJECT_SCHEMA` varchar(64) DEFAULT NULL COMMENT '庫名',

  `OBJECT_NAME` varchar(512) DEFAULT NULL COMMENT '文件名、表名、IP:SOCK值',

  `OBJECT_TYPE` varchar(64) DEFAULT NULL COMMENT 'FILE、TABLE、TEMPORARY TABLE',

  `INDEX_NAME` varchar(64) DEFAULT NULL COMMENT '索引名',

  `OBJECT_INSTANCE_BEGIN` bigint(20) unsigned NOT NULL COMMENT '內(nèi)存地址',

  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL COMMENT '該事件對(duì)應(yīng)的父事件ID',

  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL COMMENT '父事件類型(STATEMENT, STAGE, WAIT)',

  `OPERATION` varchar(32) NOT NULL COMMENT '操作類型(lock, read, write)',

  `NUMBER_OF_BYTES` bigint(20) DEFAULT NULL COMMENT '',

  `FLAGS` int(10) unsigned DEFAULT NULL COMMENT '標(biāo)記'

) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8

四:Stage 表 

1,events_stages_current:記錄了當(dāng)前線程所處的執(zhí)行階段

2,events_stages_history:記錄了當(dāng)前線程所處的執(zhí)行階段10條歷史記錄

3,events_stages_history_long:記錄了當(dāng)前線程所處的執(zhí)行階段10000條歷史記錄

表結(jié)構(gòu)定義如下:

CREATE TABLE `events_stages_current` (

  `THREAD_ID` bigint(20) unsigned NOT NULL COMMENT '線程ID',

  `EVENT_ID` bigint(20) unsigned NOT NULL COMMENT '事件ID',

  `END_EVENT_ID` bigint(20) unsigned DEFAULT NULL COMMENT '結(jié)束事件ID',

  `EVENT_NAME` varchar(128) NOT NULL COMMENT '事件名稱',

  `SOURCE` varchar(64) DEFAULT NULL COMMENT '源碼位置',

  `TIMER_START` bigint(20) unsigned DEFAULT NULL COMMENT '事件開始時(shí)間(皮秒)',

  `TIMER_END` bigint(20) unsigned DEFAULT NULL COMMENT '事件結(jié)束結(jié)束時(shí)間(皮秒)',

  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL COMMENT '事件等待時(shí)間(皮秒)',

  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL COMMENT '該事件對(duì)應(yīng)的父事件ID',

  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL COMMENT '父事件類型(STATEMENT, STAGE, WAIT)'

) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8

五:Statement 表

1,events_statements_current:通過 thread_id+event_id可以唯一確定一條記錄。Statments表只記錄最頂層的請(qǐng)求,SQL語句或是COMMAND,每條語句一行。event_name形式為statement/sql/*,或statement/com/*

2,events_statements_history

3,events_statements_history_long

表結(jié)構(gòu)定義如下:

CREATE TABLE `events_statements_current` (

  `THREAD_ID` bigint(20) unsigned NOT NULL COMMENT '線程ID',

  `EVENT_ID` bigint(20) unsigned NOT NULL COMMENT '事件ID',

  `END_EVENT_ID` bigint(20) unsigned DEFAULT NULL COMMENT '結(jié)束事件ID',

  `EVENT_NAME` varchar(128) NOT NULL COMMENT '事件名稱',

  `SOURCE` varchar(64) DEFAULT NULL COMMENT '源碼位置',

  `TIMER_START` bigint(20) unsigned DEFAULT NULL COMMENT '事件開始時(shí)間(皮秒)',

  `TIMER_END` bigint(20) unsigned DEFAULT NULL COMMENT '事件結(jié)束結(jié)束時(shí)間(皮秒)',

  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL COMMENT '事件等待時(shí)間(皮秒)',

  `LOCK_TIME` bigint(20) unsigned NOT NULL COMMENT '鎖時(shí)間',

  `SQL_TEXT` longtext COMMENT '記錄SQL語句',

  `DIGEST` varchar(32) DEFAULT NULL COMMENT '對(duì)SQL_TEXT做MD5產(chǎn)生的32位字符串',

  `DIGEST_TEXT` longtext COMMENT '將語句中值部分用問號(hào)代替,用于SQL語句歸類',

  `CURRENT_SCHEMA` varchar(64) DEFAULT NULL COMMENT '默認(rèn)的數(shù)據(jù)庫名',

  `OBJECT_TYPE` varchar(64) DEFAULT NULL COMMENT '保留字段',

  `OBJECT_SCHEMA` varchar(64) DEFAULT NULL COMMENT '保留字段',

  `OBJECT_NAME` varchar(64) DEFAULT NULL COMMENT '保留字段',

  `OBJECT_INSTANCE_BEGIN` bigint(20) unsigned DEFAULT NULL COMMENT '內(nèi)存地址',

  `MYSQL_ERRNO` int(11) DEFAULT NULL COMMENT '',

  `RETURNED_SQLSTATE` varchar(5) DEFAULT NULL COMMENT '',

  `MESSAGE_TEXT` varchar(128) DEFAULT NULL COMMENT '信息',

  `ERRORS` bigint(20) unsigned NOT NULL COMMENT '錯(cuò)誤數(shù)目',

  `WARNINGS` bigint(20) unsigned NOT NULL COMMENT '警告數(shù)目',

  `ROWS_AFFECTED` bigint(20) unsigned NOT NULL COMMENT '影響的數(shù)目',

  `ROWS_SENT` bigint(20) unsigned NOT NULL COMMENT '返回的記錄數(shù)',

  `ROWS_EXAMINED` bigint(20) unsigned NOT NULL COMMENT '讀取掃描的記錄數(shù)目',

  `CREATED_TMP_DISK_TABLES` bigint(20) unsigned NOT NULL COMMENT '創(chuàng)建磁盤臨時(shí)表數(shù)目',

  `CREATED_TMP_TABLES` bigint(20) unsigned NOT NULL COMMENT '創(chuàng)建臨時(shí)表數(shù)目',

  `SELECT_FULL_JOIN` bigint(20) unsigned NOT NULL COMMENT 'join時(shí),第一個(gè)表為全表掃描的數(shù)目',

  `SELECT_FULL_RANGE_JOIN` bigint(20) unsigned NOT NULL COMMENT '引用表采用range方式掃描的數(shù)目',

  `SELECT_RANGE` bigint(20) unsigned NOT NULL COMMENT 'join時(shí),第一個(gè)表采用range方式掃描的數(shù)目',

  `SELECT_RANGE_CHECK` bigint(20) unsigned NOT NULL COMMENT '',

  `SELECT_SCAN` bigint(20) unsigned NOT NULL COMMENT 'join時(shí),第一個(gè)表位全表掃描的數(shù)目',

  `SORT_MERGE_PASSES` bigint(20) unsigned NOT NULL COMMENT '',

  `SORT_RANGE` bigint(20) unsigned NOT NULL COMMENT '范圍排序數(shù)目',

  `SORT_ROWS` bigint(20) unsigned NOT NULL COMMENT '排序的記錄數(shù)目',

  `SORT_SCAN` bigint(20) unsigned NOT NULL COMMENT '全表排序數(shù)目',

  `NO_INDEX_USED` bigint(20) unsigned NOT NULL COMMENT '沒有使用索引數(shù)目',

  `NO_GOOD_INDEX_USED` bigint(20) unsigned NOT NULL COMMENT '',

  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL COMMENT '該事件對(duì)應(yīng)的父事件ID',

  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL COMMENT '父事件類型(STATEMENT, STAGE, WAIT)'

) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8

六:Connection 表

1,users:記錄用戶連接數(shù)信息

2,hosts:記錄了主機(jī)連接數(shù)信息

3,accounts:記錄了用戶主機(jī)連接數(shù)信息

zjy@performance_schema 12:03:27>select * from users;

+------------------+---------------------+-------------------+

| USER             | CURRENT_CONNECTIONS | TOTAL_CONNECTIONS |

+------------------+---------------------+-------------------+

| debian-sys-maint |                   |                36 |

| zjy              |                   1 |             22285 |

| dchat_php        |                   |             37864 |

| dxyslave         |                   2 |                 9 |

| nagios           |                   |             10770 |

| dchat_data       |                 140 |           2233023 |

| NULL             |                   |             15866 |

| dchat_api        |                 160 |           2754212 |

| mha_data         |                   1 |                36 |

| backup           |                   |                15 |

| cacti            |                   |              4312 |

| kol              |                  10 |            172414 |

+------------------+---------------------+-------------------+

12 rows in set (0.00 sec)

zjy@performance_schema 12:03:34>select * from hosts;

+-----------------+---------------------+-------------------+

| HOST            | CURRENT_CONNECTIONS | TOTAL_CONNECTIONS |

+-----------------+---------------------+-------------------+

| 192.168.100.218 |                 150 |           2499422 |

| 192.168.100.240 |                  10 |            172429 |

| 192.168.100.139 |                    |               698 |

| 192.168.100.21  |                   |                 2 |

| 192.168.100.220 |                 150 |           2526136 |

| 192.168.100.25  |                   1 |                 7 |

| NULL            |                    |             15867 |

| 192.168.100.241 |                   |             21558 |

| 192.168.100.191 |                   1 |                34 |

| localhost       |                   |             10807 |

| 192.168.100.118 |                   1 |                 2 |

| 192.168.100.251 |                   |              4312 |

| 192.168.100.23  |                   1 |                31 |

| 192.168.100.193 |                   |                15 |

+-----------------+---------------------+-------------------+

14 rows in set (0.01 sec)

zjy@performance_schema 12:05:21>select * from accounts;

+------------------+-----------------+---------------------+-------------------+

| USER             | HOST            | CURRENT_CONNECTIONS | TOTAL_CONNECTIONS |

+------------------+-----------------+---------------------+-------------------+

| cacti            | 192.168.100.251 |                   |              4313 |

| debian-sys-maint | localhost       |                   |                36 |

| backup           | 192.168.100.193 |                   |                15 |

| dchat_api        | 192.168.100.220 |                  80 |           1382585 |

| dchat_php        | 192.168.100.220 |                   |             20292 |

| zjy              | 192.168.100.139 |                   |               698 |

| zjy              | 192.168.100.241 |                   |             21558 |

| mha_data         | 192.168.100.191 |                   1 |                34 |

| dxyslave         | 192.168.100.118 |                   1 |                 2 |

| kol              | 192.168.100.240 |                  10 |            172431 |

| dxyslave         | 192.168.100.25  |                   1 |                 7 |

| dchat_data       | 192.168.100.218 |                  70 |           1109974 |

| zjy              | 192.168.100.23  |                   1 |                31 |

| dchat_php        | 192.168.100.218 |                   |             17572 |

| dchat_data       | 192.168.100.220 |                  70 |           1123306 |

| NULL             | NULL            |                   |             15868 |

| mha_data         | 192.168.100.21  |                   |                 2 |

| dchat_api        | 192.168.100.218 |                  80 |           1371918 |

| nagios           | localhost       |                   |             10771 |

+------------------+-----------------+---------------------+-------------------+

View Code

七:Summary 表: Summary表聚集了各個(gè)維度的統(tǒng)計(jì)信息包括表維度,索引維度,會(huì)話維度,語句維度和鎖維度的統(tǒng)計(jì)信息

1,events_waits_summary_global_by_event_name:按等待事件類型聚合,每個(gè)事件一條記錄

CREATE TABLE `events_waits_summary_global_by_event_name` (

  `EVENT_NAME` varchar(128) NOT NULL COMMENT '事件名稱',

  `COUNT_STAR` bigint(20) unsigned NOT NULL COMMENT '事件計(jì)數(shù)',

  `SUM_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '總的等待時(shí)間',

  `MIN_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '最小等待時(shí)間',

  `AVG_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '平均等待時(shí)間',

  `MAX_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '最大等待時(shí)間'

) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8

2,events_waits_summary_by_instance:按等待事件對(duì)象聚合,同一種等待事件,可能有多個(gè)實(shí)例,每個(gè)實(shí)例有不同的內(nèi)存地址,因此
event_name+object_instance_begin唯一確定一條記錄。

CREATE TABLE `events_waits_summary_by_instance` (

  `EVENT_NAME` varchar(128) NOT NULL COMMENT '事件名稱',

  `OBJECT_INSTANCE_BEGIN` bigint(20) unsigned NOT NULL COMMENT '內(nèi)存地址',

  `COUNT_STAR` bigint(20) unsigned NOT NULL COMMENT '事件計(jì)數(shù)',

  `SUM_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '總的等待時(shí)間',

  `MIN_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '最小等待時(shí)間',

  `AVG_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '平均等待時(shí)間',

  `MAX_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '最大等待時(shí)間'

) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8

3,events_waits_summary_by_thread_by_event_name:按每個(gè)線程和事件來統(tǒng)計(jì),thread_id+event_name唯一確定一條記錄。

CREATE TABLE `events_waits_summary_by_thread_by_event_name` (

  `THREAD_ID` bigint(20) unsigned NOT NULL COMMENT '線程ID',

  `EVENT_NAME` varchar(128) NOT NULL COMMENT '事件名稱',

  `COUNT_STAR` bigint(20) unsigned NOT NULL COMMENT '事件計(jì)數(shù)',

  `SUM_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '總的等待時(shí)間',

  `MIN_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '最小等待時(shí)間',

  `AVG_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '平均等待時(shí)間',

  `MAX_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '最大等待時(shí)間'

) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8

4,events_stages_summary_global_by_event_name:按事件階段類型聚合,每個(gè)事件一條記錄,表結(jié)構(gòu)同上。

5,events_stages_summary_by_thread_by_event_name:按每個(gè)線程和事件來階段統(tǒng)計(jì),表結(jié)構(gòu)同上。

6,events_statements_summary_by_digest:按照事件的語句進(jìn)行聚合。

CREATE TABLE `events_statements_summary_by_digest` (

  `SCHEMA_NAME` varchar(64) DEFAULT NULL COMMENT '庫名',

  `DIGEST` varchar(32) DEFAULT NULL COMMENT '對(duì)SQL_TEXT做MD5產(chǎn)生的32位字符串。如果為consumer表中沒有打開statement_digest選項(xiàng),則為NULL',

  `DIGEST_TEXT` longtext COMMENT '將語句中值部分用問號(hào)代替,用于SQL語句歸類。如果為consumer表中沒有打開statement_digest選項(xiàng),則為NULL。',

  `COUNT_STAR` bigint(20) unsigned NOT NULL COMMENT '事件計(jì)數(shù)',

  `SUM_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '總的等待時(shí)間',

  `MIN_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '最小等待時(shí)間',

  `AVG_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '平均等待時(shí)間',

  `MAX_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT '最大等待時(shí)間',

  `SUM_LOCK_TIME` bigint(20) unsigned NOT NULL COMMENT '鎖時(shí)間總時(shí)長(zhǎng)',

  `SUM_ERRORS` bigint(20) unsigned NOT NULL COMMENT '錯(cuò)誤數(shù)的總',

  `SUM_WARNINGS` bigint(20) unsigned NOT NULL COMMENT '警告的總數(shù)',

  `SUM_ROWS_AFFECTED` bigint(20) unsigned NOT NULL COMMENT '影響的總數(shù)目',

  `SUM_ROWS_SENT` bigint(20) unsigned NOT NULL COMMENT '返回總數(shù)目',

  `SUM_ROWS_EXAMINED` bigint(20) unsigned NOT NULL COMMENT '總的掃描的數(shù)目',

  `SUM_CREATED_TMP_DISK_TABLES` bigint(20) unsigned NOT NULL COMMENT '創(chuàng)建磁盤臨時(shí)表的總數(shù)目',

  `SUM_CREATED_TMP_TABLES` bigint(20) unsigned NOT NULL COMMENT '創(chuàng)建臨時(shí)表的總數(shù)目',

  `SUM_SELECT_FULL_JOIN` bigint(20) unsigned NOT NULL COMMENT '第一個(gè)表全表掃描的總數(shù)目',

  `SUM_SELECT_FULL_RANGE_JOIN` bigint(20) unsigned NOT NULL COMMENT '總的采用range方式掃描的數(shù)目',

  `SUM_SELECT_RANGE` bigint(20) unsigned NOT NULL COMMENT '第一個(gè)表采用range方式掃描的總數(shù)目',

  `SUM_SELECT_RANGE_CHECK` bigint(20) unsigned NOT NULL COMMENT '',

  `SUM_SELECT_SCAN` bigint(20) unsigned NOT NULL COMMENT '第一個(gè)表位全表掃描的總數(shù)目',

  `SUM_SORT_MERGE_PASSES` bigint(20) unsigned NOT NULL COMMENT '',

  `SUM_SORT_RANGE` bigint(20) unsigned NOT NULL COMMENT '范圍排序總數(shù)',

  `SUM_SORT_ROWS` bigint(20) unsigned NOT NULL COMMENT '排序的記錄總數(shù)目',

  `SUM_SORT_SCAN` bigint(20) unsigned NOT NULL COMMENT '第一個(gè)表排序掃描總數(shù)目',

  `SUM_NO_INDEX_USED` bigint(20) unsigned NOT NULL COMMENT '沒有使用索引總數(shù)',

  `SUM_NO_GOOD_INDEX_USED` bigint(20) unsigned NOT NULL COMMENT '',

  `FIRST_SEEN` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '第一次執(zhí)行時(shí)間',

  `LAST_SEEN` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '最后一次執(zhí)行時(shí)間'

) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8

7,events_statements_summary_global_by_event_name:按照事件的語句進(jìn)行聚合。表結(jié)構(gòu)同上。

8,events_statements_summary_by_thread_by_event_name:按照線程和事件的語句進(jìn)行聚合,表結(jié)構(gòu)同上。

9,file_summary_by_instance:按事件類型統(tǒng)計(jì)(物理IO維度

10,file_summary_by_event_name:具體文件統(tǒng)計(jì)(物理IO維度

9和10一起說明:

統(tǒng)計(jì)IO操作:COUNT_STAR,SUM_TIMER_WAIT,MIN_TIMER_WAIT,AVG_TIMER_WAIT,MAX_TIMER_WAIT

統(tǒng)計(jì)讀      :COUNT_READ,SUM_TIMER_READ,MIN_TIMER_READ,AVG_TIMER_READ,MAX_TIMER_READ, SUM_NUMBER_OF_BYTES_READ

統(tǒng)計(jì)寫      :COUNT_WRITE,SUM_TIMER_WRITE,MIN_TIMER_WRITE,AVG_TIMER_WRITE,MAX_TIMER_WRITE, SUM_NUMBER_OF_BYTES_WRITE

統(tǒng)計(jì)其他IO事件,比如create,delete,open,close等:COUNT_MISC,SUM_TIMER_MISC,MIN_TIMER_MISC,AVG_TIMER_MISC,MAX_TIMER_MISC

11,table_io_waits_summary_by_table:根據(jù)wait/io/table/sql/handler,聚合每個(gè)表的I/O操作(邏輯IO緯度

統(tǒng)計(jì)IO操作:COUNT_STAR,SUM_TIMER_WAIT,MIN_TIMER_WAIT,AVG_TIMER_WAIT,MAX_TIMER_WAIT 

統(tǒng)計(jì)讀      :COUNT_READ,SUM_TIMER_READ,MIN_TIMER_READ,AVG_TIMER_READ,MAX_TIMER_READ

              :COUNT_FETCH,SUM_TIMER_FETCH,MIN_TIMER_FETCH,AVG_TIMER_FETCH, MAX_TIMER_FETCH

統(tǒng)計(jì)寫      :COUNT_WRITE,SUM_TIMER_WRITE,MIN_TIMER_WRITE,AVG_TIMER_WRITE,MAX_TIMER_WRITE

INSERT統(tǒng)計(jì),相應(yīng)的還有DELETE和UPDATE統(tǒng)計(jì):COUNT_INSERT,SUM_TIMER_INSERT,MIN_TIMER_INSERT,AVG_TIMER_INSERT,MAX_TIMER_INSERT

12,table_io_waits_summary_by_index_usage:與table_io_waits_summary_by_table類似,按索引維度統(tǒng)計(jì)

13,table_lock_waits_summary_by_table:聚合了表鎖等待事件,包括internal lock 和 external lock

internal lock通過SQL層函數(shù)thr_lock調(diào)用,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則通過接口函數(shù)handler::external_lock調(diào)用存儲(chǔ)引擎層,OPERATION列的值為:read external、write external

14,Connection Summaries表:account、user、host

events_waits_summary_by_account_by_event_name
events_waits_summary_by_user_by_event_name
events_waits_summary_by_host_by_event_name 
events_stages_summary_by_account_by_event_name
events_stages_summary_by_user_by_event_name
events_stages_summary_by_host_by_event_name 
events_statements_summary_by_account_by_event_name
events_statements_summary_by_user_by_event_name
events_statements_summary_by_host_by_event_name

15,socket_summary_by_instance、socket_summary_by_event_name:socket聚合統(tǒng)計(jì)表。

八:其他相關(guān)表

1,performance_timers:系統(tǒng)支持的統(tǒng)計(jì)時(shí)間單位

2,threads:監(jiān)視服務(wù)端的當(dāng)前運(yùn)行的線程

統(tǒng)計(jì)應(yīng)用:

      關(guān)于SQL維度的統(tǒng)計(jì)信息主要集中在events_statements_summary_by_digest表中,通過將SQL語句抽象出digest,可以統(tǒng)計(jì)某類SQL語句在各個(gè)維度的統(tǒng)計(jì)信息

1,哪個(gè)SQL執(zhí)行最多:

zjy@performance_schema 11:36:22>SELECT SCHEMA_NAME,DIGEST_TEXT,COUNT_STAR,SUM_ROWS_SENT,SUM_ROWS_EXAMINED,FIRST_SEEN,LAST_SEEN FROM events_statements_summary_by_digest ORDER BY COUNT_STAR desc LIMIT 1\G

*************************** 1. row ***************************

      SCHEMA_NAME: dchat

      DIGEST_TEXT: SELECT ...

       COUNT_STAR: 1161210102

    SUM_ROWS_SENT: 1161207842

SUM_ROWS_EXAMINED:

       FIRST_SEEN: 2016-02-17 00:36:46

        LAST_SEEN: 2016-03-07 11:36:29

各個(gè)字段的注釋可以看上面的表結(jié)構(gòu)說明:從2月17號(hào)到3月7號(hào)該SQL執(zhí)行了1161210102次。

2,哪個(gè)SQL平均響應(yīng)時(shí)間最多:

zjy@performance_schema 11:36:28>SELECT SCHEMA_NAME,DIGEST_TEXT,COUNT_STAR,AVG_TIMER_WAIT,SUM_ROWS_SENT,SUM_ROWS_EXAMINED,FIRST_SEEN,LAST_SEEN FROM events_statements_summary_by_digest ORDER BY AVG_TIMER_WAIT desc LIMIT 1\G

*************************** 1. row ***************************

      SCHEMA_NAME: dchat

      DIGEST_TEXT: SELECT ...

       COUNT_STAR: 1

   AVG_TIMER_WAIT: 273238183964000

    SUM_ROWS_SENT: 50208

SUM_ROWS_EXAMINED: 5565651

       FIRST_SEEN: 2016-02-22 13:27:33

        LAST_SEEN: 2016-02-22 13:27:33

各個(gè)字段的注釋可以看上面的表結(jié)構(gòu)說明:從2月17號(hào)到3月7號(hào)該SQL平均響應(yīng)時(shí)間273238183964000皮秒(1000000000000皮秒=1秒)

3,哪個(gè)SQL掃描的行數(shù)最多:

SUM_ROWS_EXAMINED

4,哪個(gè)SQL使用的臨時(shí)表最多:

SUM_CREATED_TMP_DISK_TABLES、SUM_CREATED_TMP_TABLES

5,哪個(gè)SQL返回的結(jié)果集最多:

SUM_ROWS_SENT

6,哪個(gè)SQL排序數(shù)最多:

SUM_SORT_ROWS

通過上述指標(biāo)我們可以間接獲得某類SQL的邏輯IO(SUM_ROWS_EXAMINED),CPU消耗(SUM_SORT_ROWS),網(wǎng)絡(luò)帶寬(SUM_ROWS_SENT)的對(duì)比。

通過file_summary_by_instance表,可以獲得系統(tǒng)運(yùn)行到現(xiàn)在,哪個(gè)文件(表)物理IO最多,這可能意味著這個(gè)表經(jīng)常需要訪問磁盤IO。

7,哪個(gè)表、文件邏輯IO最多(熱數(shù)據(jù)):

zjy@performance_schema 12:16:18>SELECT FILE_NAME,EVENT_NAME,COUNT_READ,SUM_NUMBER_OF_BYTES_READ,COUNT_WRITE,SUM_NUMBER_OF_BYTES_WRITE FROM file_summary_by_instance ORDER BY SUM_NUMBER_OF_BYTES_READ+SUM_NUMBER_OF_BYTES_WRITE DESC LIMIT 2\G

*************************** 1. row ***************************

                FILE_NAME: /var/lib/mysql/ibdata1  #文件


當(dāng)前名稱:怎么理解MySQL5.6中的PERFORMANCE_SCHEM
標(biāo)題網(wǎng)址:http://weahome.cn/article/pjdcie.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部