14.17 InnoDB 与 MySQL 性能架构的集成
本节简要介绍了InnoDB
与 Performance Schema 的集成。有关全面的性能架构文档,请参见第 25 章,MySQL 性能模式。
您可以使用 MySQL 性能架构功能来分析某些内部InnoDB
操作。这种类型的调整主要面向评估优化策略以克服性能瓶颈的 maven 用户。 DBA 还可以使用此功能进行容量规划,以查看其典型工作负载在 CPU,RAM 和磁盘存储的特定组合下是否遇到任何性能瓶颈。如果可以,则判断是否可以通过增加系统某些部分的容量来提高性能。
要使用此功能检查InnoDB
性能,请执行以下操作:
-
您通常必须熟悉如何使用性能架构功能。例如,您应该知道如何启用工具和使用者,以及如何查询
performance_schema
table 以检索数据。有关介绍性概述,请参见第 25.1 节“性能架构快速入门”。 -
您应该熟悉
InnoDB
可用的 Performance Schema 工具。要查看与InnoDB
相关的乐器,您可以在setup_instrumentstable 中查询包含“innodb
”的乐器名称。
mysql> SELECT *
FROM performance_schema.setup_instruments
WHERE NAME LIKE '%innodb%';
+-------------------------------------------------------+---------+-------+
| NAME | ENABLED | TIMED |
+-------------------------------------------------------+---------+-------+
| wait/synch/mutex/innodb/commit_cond_mutex | NO | NO |
| wait/synch/mutex/innodb/innobase_share_mutex | NO | NO |
| wait/synch/mutex/innodb/autoinc_mutex | NO | NO |
| wait/synch/mutex/innodb/buf_pool_mutex | NO | NO |
| wait/synch/mutex/innodb/buf_pool_zip_mutex | NO | NO |
| wait/synch/mutex/innodb/cache_last_read_mutex | NO | NO |
| wait/synch/mutex/innodb/dict_foreign_err_mutex | NO | NO |
| wait/synch/mutex/innodb/dict_sys_mutex | NO | NO |
| wait/synch/mutex/innodb/recalc_pool_mutex | NO | NO |
| wait/synch/mutex/innodb/file_format_max_mutex | NO | NO |
...
| wait/io/file/innodb/innodb_data_file | YES | YES |
| wait/io/file/innodb/innodb_log_file | YES | YES |
| wait/io/file/innodb/innodb_temp_file | YES | YES |
| stage/innodb/alter table (end) | YES | YES |
| stage/innodb/alter table (flush) | YES | YES |
| stage/innodb/alter table (insert) | YES | YES |
| stage/innodb/alter table (log apply index) | YES | YES |
| stage/innodb/alter table (log apply table) | YES | YES |
| stage/innodb/alter table (merge sort) | YES | YES |
| stage/innodb/alter table (read PK and internal sort) | YES | YES |
| stage/innodb/buffer pool load | YES | YES |
| memory/innodb/buf_buf_pool | NO | NO |
| memory/innodb/dict_stats_bg_recalc_pool_t | NO | NO |
| memory/innodb/dict_stats_index_map_t | NO | NO |
| memory/innodb/dict_stats_n_diff_on_level | NO | NO |
| memory/innodb/other | NO | NO |
| memory/innodb/row_log_buf | NO | NO |
| memory/innodb/row_merge_sort | NO | NO |
| memory/innodb/std | NO | NO |
| memory/innodb/sync_debug_latches | NO | NO |
| memory/innodb/trx_sys_t::rw_trx_ids | NO | NO |
...
+-------------------------------------------------------+---------+-------+
155 rows in set (0.00 sec)
有关已检测的InnoDB
对象的其他信息,您可以查询 Performance Schema instances tables,其中提供了有关已检测的对象的其他信息。与InnoDB
相关的实例 table 包括:
-
mutex_instancestable
-
rwlock_instancestable
-
cond_instancestable
-
file_instancestable
-
Note
与InnoDB
缓冲池相关的互斥锁和 RW 锁不包括在本报告中; SHOW ENGINE INNODB MUTEX
命令的输出也是如此。
例如,要查看有关在执行文件 I/O 检测时性能架构看到的检测到的InnoDB
文件对象的信息,您可以发出以下查询:
mysql> SELECT *
FROM performance_schema.file_instances
WHERE EVENT_NAME LIKE '%innodb%'\G
*************************** 1. row ***************************
FILE_NAME: /path/to/mysql-5.7/data/ibdata1
EVENT_NAME: wait/io/file/innodb/innodb_data_file
OPEN_COUNT: 3
*************************** 2. row ***************************
FILE_NAME: /path/to/mysql-5.7/data/ib_logfile0
EVENT_NAME: wait/io/file/innodb/innodb_log_file
OPEN_COUNT: 2
*************************** 3. row ***************************
FILE_NAME: /path/to/mysql-5.7/data/ib_logfile1
EVENT_NAME: wait/io/file/innodb/innodb_log_file
OPEN_COUNT: 2
*************************** 4. row ***************************
FILE_NAME: /path/to/mysql-5.7/data/mysql/engine_cost.ibd
EVENT_NAME: wait/io/file/innodb/innodb_data_file
OPEN_COUNT: 3
...
-
您应该熟悉存储
InnoDB
事件数据的performance_schema
table。与InnoDB
相关的事件相关的 table 包括: -
Wait Eventtable,用于存储 await 事件。
-
Summarytable,这些 table 提供了一段时间内终止事件的汇总信息。摘要 table 包括文件 I/O 汇总 table,它们汇总有关 I/O 操作的信息。
-
Stage Event个 table,用于存储
InnoDB
ALTER TABLE的事件数据和缓冲池加载操作。有关更多信息,请参见第 14.17.1 节“使用性能模式监视 InnoDBtable 的 ALTER TABLE 进度”和使用性能架构监视缓冲池加载进度。
-
如果只对与InnoDB
相关的对象感兴趣,请在查询这些 table 时使用子句WHERE EVENT_NAME LIKE '%innodb%'
或WHERE NAME LIKE '%innodb%'
(根据需要)。