14.17 InnoDB 与 MySQL 性能架构的集成

本节简要介绍了InnoDB与 Performance Schema 的集成。有关全面的性能架构文档,请参见第 25 章,MySQL 性能模式

您可以使用 MySQL 性能架构功能来分析某些内部InnoDB操作。这种类型的调整主要面向评估优化策略以克服性能瓶颈的 maven 用户。 DBA 还可以使用此功能进行容量规划,以查看其典型工作负载在 CPU,RAM 和磁盘存储的特定组合下是否遇到任何性能瓶颈。如果可以,则判断是否可以通过增加系统某些部分的容量来提高性能。

要使用此功能检查InnoDB性能,请执行以下操作:

  • 您通常必须熟悉如何使用性能架构功能。例如,您应该知道如何启用工具和使用者,以及如何查询performance_schematable 以检索数据。有关介绍性概述,请参见第 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 包括:

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相关的对象感兴趣,请在查询这些 table 时使用子句WHERE EVENT_NAME LIKE '%innodb%'WHERE NAME LIKE '%innodb%'(根据需要)。