mysql5.6 pt-query-digest_pt-query-digest安装及分析
slow log 設(shè)置:
cat my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
#skip-grant-tables
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
log_bin=mysql-bin
slow_query_log=on
long_query_time=1
#long_query_time = 1
slow_query_log = 1
slow_query_log_file = slow.log
************************************************************
mysql查看:
mysql> show variables like "%query%";
+------------------------------+----------+
| Variable_name ? ? ? ? ? ? ? ?| Value ? ?|
+------------------------------+----------+
| binlog_rows_query_log_events | OFF ? ? ?|
| ft_query_expansion_limit ? ? | 20 ? ? ? |
| have_query_cache ? ? ? ? ? ? | YES ? ? ?|
| long_query_time ? ? ? ? ? ? ?| 1.000000 |
| query_alloc_block_size ? ? ? | 8192 ? ? |
| query_cache_limit ? ? ? ? ? ?| 1048576 ?|
| query_cache_min_res_unit ? ? | 4096 ? ? |
| query_cache_size ? ? ? ? ? ? | 1048576 ?|
| query_cache_type ? ? ? ? ? ? | OFF ? ? ?|
| query_cache_wlock_invalidate | OFF ? ? ?|
| query_prealloc_size ? ? ? ? ?| 8192 ? ? |
| slow_query_log ? ? ? ? ? ? ? | ON ? ? ? |
| slow_query_log_file ? ? ? ? ?| slow.log |
+------------------------------+----------+
13 rows in set (0.00 sec)
pt-query-digest:分析
常用選項(xiàng):??—create-review-table? ???當(dāng)使用—review參數(shù),把分析結(jié)果輸出到表中
—create-history-table? ???但是用—history參數(shù),把分析結(jié)果輸出到表中
—filter? ???對(duì)輸入的慢查詢(xún)按指定的字符串進(jìn)行匹配過(guò)濾后,在進(jìn)行分析
—limit? ???限制輸出結(jié)果百分比或數(shù)量,默認(rèn)值是20,即將最慢的20條語(yǔ)句輸出
—host? ???HostName
—user? ???用戶(hù)名
—password? ???密碼
—history? ???將分析結(jié)果保存到表中,分析結(jié)果比較詳細(xì)
—review? ?? ?將分析結(jié)果保存到表中
—output? ???分析結(jié)果輸出類(lèi)型
—since? ???從什么時(shí)間開(kāi)始分析,值為字符串
—until? ???截止時(shí)間,配合since一起分析
分析結(jié)果:
其中:
Overall:總共有多少條查詢(xún)
unique:唯一查詢(xún)數(shù)量
Time range:查詢(xún)執(zhí)行的時(shí)間范圍
total:總計(jì)
min:最小
max:最大
avg:平均
95%:95%的查詢(xún)時(shí)間,重點(diǎn)分析
median:中位數(shù),把所有值從小到大排列,位置位于中間那個(gè)數(shù)
詳細(xì)的分析結(jié)果:
Response:總的響應(yīng)時(shí)間
time:該查詢(xún)?cè)诒敬畏治鲋姓加玫臅r(shí)間比
Calls:執(zhí)行次數(shù)
R/Call:平均每次執(zhí)行的響應(yīng)時(shí)間
Item:查詢(xún)對(duì)象
每一條查詢(xún)的詳細(xì)分析結(jié)果:
ID:查詢(xún)的ID號(hào),和上圖的Query ID對(duì)應(yīng)
Databases: 數(shù)據(jù)庫(kù)名
Users:執(zhí)行的用戶(hù)
Query_time distribution:查詢(xún)的時(shí)間分布(此圖說(shuō)明,查詢(xún)幾乎都在1ms-10ms之間)
Tables:查詢(xún)涉及到的表
EXPLAIN:SQL語(yǔ)句
pt-query-digest安裝:
yum -y install perl perl-IO-Socket-SSL perl-DBD-MySQL perl-Time-HiRes
*********
rpm包安裝:
rpm -ivh percona-toolkit-2.1.7-1.noarch.rpm
warning: percona-toolkit-2.1.7-1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
Preparing... ? ? ? ? ? ? ? ?########################################### [100%]
1:percona-toolkit ? ? ? ?########################################### [100%]
使用pt-query-digest分析滿(mǎn)查詢(xún)輸出結(jié)果:
pt-query-digest slow.log
# 450ms user time, 60ms system time, 23.30M rss, 197.64M vsz
該工具執(zhí)行日志分析的用戶(hù)時(shí)間,系統(tǒng)時(shí)間,物理內(nèi)存占用大小,虛擬內(nèi)存占用大小
# Current date: Sat Aug ?2 17:33:05 2014
工具執(zhí)行時(shí)間
# Hostname: cj149
運(yùn)行分析工具的主機(jī)名
# Files: slow.log
被分析的文件名
# Overall: 6 total, 1 unique, 0.06 QPS, 0.24x concurrency ________________
語(yǔ)句總數(shù)量,唯一的語(yǔ)句數(shù)量,QPS,并發(fā)數(shù)
# Time range: 2014-08-02 17:05:48 to 17:07:30
日志記錄的時(shí)間范圍
# Attribute ? ? ? ? ?total ? ? min ? ? max ? ? avg ? ? 95% ?stddev ?median
屬性總計(jì)最小最大平均95% ? ? ?標(biāo)準(zhǔn) ? ? ? ??中等
# ============ ? ? ======= ======= ======= ======= ======= ======= =======
# Exec time ? ? ? ? ? ?24s ? ? ?3s ? ? ?6s ? ? ?4s ? ? ?6s ? ? ?1s ? ? ?4s
語(yǔ)句執(zhí)行時(shí)間
# Lock time ? ? ? ? ? ? ?0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0
鎖占用時(shí)間
# Rows sent ? ? ? ? ? ? ?6 ? ? ? 1 ? ? ? 1 ? ? ? 1 ? ? ? 1 ? ? ? 0 ? ? ? 1
發(fā)送到客戶(hù)端的行數(shù)
# Rows examine ? ? ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0
select語(yǔ)句掃描行數(shù)
# Query size ? ? ? ? ? ?90 ? ? ?15 ? ? ?15 ? ? ?15 ? ? ?15 ? ? ? 0 ? ? ?15
查詢(xún)的字符數(shù)
# Profile
# Rank Query ID ? ? ? ? ? Response time ?Calls R/Call Apdx V/M ? Item
# ==== ================== ============== ===== ====== ==== ===== ======
# ? ?1 0xF9A57DD5A41825CA 24.0022 100.0% ? ? 6 4.0004 0.33 ?0.31 SELECT
Rank:所有語(yǔ)句的排名,默認(rèn)按查詢(xún)時(shí)間降序排列,通過(guò)--order-by指定
Query ID?:語(yǔ)句的ID,(去掉多余空格和文本字符,計(jì)算hash值)
Response time:響應(yīng)時(shí)間,占所有響應(yīng)時(shí)間的百分比
Calls:查詢(xún)執(zhí)行次數(shù)
R/Call:平均響應(yīng)時(shí)間
V/M:響應(yīng)時(shí)間Variance-to-mean的比率
Item:查詢(xún)語(yǔ)句一部分
每條查詢(xún)語(yǔ)句的分析:
# Query 1: 0.06 QPS, 0.24x concurrency, ID 0xF9A57DD5A41825CA at byte 1151
# This item is included in the report because it matches --limit.
# Scores: Apdex = 0.33 [1.0]*, V/M = 0.31
# Query_time sparkline: | ? ? ?^ |
# Time range: 2014-08-02 17:05:48 to 17:07:30
# Attribute ? ?pct ? total ? ? min ? ? max ? ? avg ? ? 95% ?stddev ?median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count ? ? ? ?100 ? ? ? 6
# Exec time ? ?100 ? ? 24s ? ? ?3s ? ? ?6s ? ? ?4s ? ? ?6s ? ? ?1s ? ? ?4s
# Lock time ? ? ?0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0
# Rows sent ? ?100 ? ? ? 6 ? ? ? 1 ? ? ? 1 ? ? ? 1 ? ? ? 1 ? ? ? 0 ? ? ? 1
# Rows examine ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0 ? ? ? 0
# Query size ? 100 ? ? ?90 ? ? ?15 ? ? ?15 ? ? ?15 ? ? ?15 ? ? ? 0 ? ? ?15
# String:
# Hosts ? ? ? ?localhost
# Users ? ? ? ?root
# Query_time distribution
# ? 1us
# ?10us
# 100us
# ? 1ms
# ?10ms
# 100ms
# ? ?1s ?################################################################
# ?10s+
# EXPLAIN /*!50100 PARTITIONS*/
select sleep(6)G
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的mysql5.6 pt-query-digest_pt-query-digest安装及分析的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: oracle 时间间隔,ORACLE
- 下一篇: IOC操作Bean管理注解方式(完全注解