mysql – 在pt-query-digest输出之上的COMMIT
作者:互联网
我一直在优化我的MySQL服务器,在调整了一些查询后,我最终得到了pt-query-digest输出顶部的COMMIT项,如下面的摘录所示:
# 322s user time, 770ms system time, 71.75M rss, 223.13M vsz
# Current date: Sat Oct 1 11:12:58 2016
# Hostname: XXXX
# Files: /home/tools/Slow10.log
# Overall: 1.08M total, 1.47k unique, 61.74 QPS, 0.17x concurrency _______
# Time range: 2016-10-01 06:15:09 to 11:06:35
# Attribute total min max avg 95% stddev median
# ============ ======= ======= ======= ======= ======= ======= =======
# Exec time 2913s 1us 14s 3ms 15ms 27ms 194us
# Lock time 123s 0 2s 113us 167us 3ms 42us
# Rows sent 1019.81k 0 8.58k 0.97 0.99 26.59 0
# Rows examine 314.86M 0 2.13M 305.82 234.30 7.13k 0
# Query size 321.03M 6 14.64k 311.81 1.14k 743.10 88.31
# Profile
# Rank Query ID Response time Calls R/Call V/M Item
# ==== ================== =============== ====== ====== ===== ============
# 1 0x813031B8BBC3B329 1676.7355 57.6% 70006 0.0240 0.02 COMMIT
# 2 0xBC10C51A724ECD57 61.8928 2.1% 211 0.2933 0.08 SELECT users
查询显示为:
# Query 1: 4.00 QPS, 0.10x concurrency, ID 0x813031B8BBC3B329 at byte 462955973
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.02
# Time range: 2016-10-01 06:15:09 to 11:06:34
# Attribute pct total min max avg 95% stddev median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count 6 70006
# Exec time 57 1677s 9us 2s 24ms 56ms 24ms 16ms
# Lock time 0 0 0 0 0 0 0 0
# Rows sent 0 0 0 0 0 0 0 0
# Rows examine 0 0 0 0 0 0 0 0
# Query size 0 410.19k 6 6 6 6 0 6
# String:
# Databases XXX_XX... (9419/13%)... 40 more
# Hosts localhost
# Query_time distribution
# 1us #
# 10us #
# 100us #
# 1ms ####
# 10ms ################################################################
# 100ms #
# 1s #
# 10s+
commit\G
关于如何优化这个的任何一个词?
如果需要进一步的信息,请告诉我!
提前致谢!
编辑2016-02-10:在任何查询优化之前的第一个分析看起来像:
# Rank Query ID Response time Calls R/Call V/M Item
# ==== ================== ================ ======= ====== ===== ==========
# 1 0x62057CDB69C17D23 18377.2125 46.3% 139328 0.1319 0.15 SELECT AAAA
# 2 0xEC77079791A0E274 6992.0443 17.6% 127446 0.0549 0.09 SELECT BBBB
# 3 0xB8A934DECC36D811 6283.1217 15.8% 247595 0.0254 0.03 UPDATE users_sessions
# 4 0x813031B8BBC3B329 2042.6094 5.1% 89046 0.0229 0.04 COMMIT
服务器有8Gb RAM,innodb_buffer_pool_size = 5G,大约有70个数据库,每个数据库有140个表.
编辑2016-10-06:
# grep innodb /etc/my.cnf
innodb_flush_method=O_DIRECT
innodb_buffer_pool_size=5G
innodb_log_buffer_size=4M
解决方法:
取证…
>您的COMMIT的中位时间:16ms.
>旋转磁盘写入的典型时间:10ms.
> innodb_flush_log_at_trx_commit的默认设置:1,表示每次提交时刷新到磁盘.
结论:杀手使用了库中的烛台.或者..你正在做的大部分是非常迅速的交易.
加速的可能方法:
> innodb_flush_log_at_trx_commit = 2 – 每秒刷新一次,而不是每次刷新一次.这不太“安全”,但对于一些用户来说,权衡是值得的.
>批量操作.而不是每个COMMIT一个INSERT,做很多INSERT. COMMIT的主要成本是刷新一次写回滚动日志,无论事务中发生了多少.
>硬件 – 固态硬盘 – 将10毫秒降至1毫秒(或类似的东西);具有电池备份写入缓存的RAID – 使写入几乎耗时0毫秒,即使不会损失安全性.
>由于一些COMMIT超过1秒,您可以查找它们并查看它们的事务是否可以改进.
标签:mysql,percona,mysql-5-5,slow-log,percona-tools 来源: https://codeday.me/bug/20190805/1591446.html