• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • 位置: MySQL 8 中文手册 -> InnoDB存储引擎

    InnoDB与MySQL 性能架构

    本节简要介绍如何InnoDB与Performance Schema集成。有关全面的Performance Schema文档,请参见MySQL Performance Schema

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

    要使用此功能来检查InnoDB性能:

    • 您通常必须熟悉如何使用性能架构功能。例如,您应该知道如何启用工具和使用者,以及如何查询performance_schema表以检索数据。有关介绍性概述,请参见“性能模式快速入门”。
    • 您应该熟悉可用于的性能架构工具InnoDB。要查看InnoDB与之相关的工具,您可以在setup_instruments表中查询包含“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/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 实例表,这些表提供了有关已检测对象的其他信息。相关的实例表InnoDB包括:

      • mutex_instances
      • rwlock_instances
      • cond_instances
      • file_instances
      注意

      InnoDB缓冲池相关的互斥锁和RW锁不包括在此范围内;这同样适用于SHOW ENGINE INNODB MUTEX命令的输出。

      例如,要查看有关InnoDB在执行文件I / O检测时性能架构看到的检测文件对象的信息,您可以发出以下查询:

      mysql> SELECT *
             FROM performance_schema.file_instances
             WHERE EVENT_NAME LIKE '%innodb%'\G
      *************************** 1. row 	***************************
       FILE_NAME	: /path/to/mysql-8.0/data/ibdata1
      EVENT_NAME	: wait/io/file/innodb/innodb_data_file
      OPEN_COUNT	: 3
      	*************************** 2. row 	***************************
       FILE_NAME	: /path/to/mysql-8.0/data/ib_logfile0
      EVENT_NAME	: wait/io/file/innodb/innodb_log_file
      OPEN_COUNT	: 2
      	*************************** 3. row 	***************************
       FILE_NAME	: /path/to/mysql-8.0/data/ib_logfile1
      EVENT_NAME	: wait/io/file/innodb/innodb_log_file
      OPEN_COUNT	: 2
      	*************************** 4. row 	***************************
       FILE_NAME	: /path/to/mysql-8.0/data/mysql/engine_cost.ibd
      EVENT_NAME	: wait/io/file/innodb/innodb_data_file
      OPEN_COUNT	: 3
      ...
      
    • 您应该熟悉performance_schema存储InnoDB事件数据的表。与InnoDB相关事件相关的表包括:

      • 在等待事件表,其存储等待事件。
      • 该汇总表,提供随时间终止事件的汇总信息。摘要表包括文件I / O摘要表,这些表汇总了有关I / O操作的信息。
      • InnoDBALTER TABLE暂存事件表,用于存储事件数据和缓冲池装入操作。有关更多信息,请参见“使用性能模式监视InnoDB表的ALTER TABLE进度”和使用性能模式监视缓冲池加载进度。

      如果您仅对与InnoDB相关的对象感兴趣,请在查询这些表时使用子句WHERE EVENT_NAME LIKE '%innodb%'WHERE NAME LIKE '%innodb%'(根据需要)。