Performance Schema 对等待事件进行检测,这些事件是需要时间的事件。在事件层级中,等待事件嵌套在阶段事件中,阶段事件又嵌套在语句事件中,语句事件嵌套在事务事件中。The Performance Schema instruments waits, which are events that take time. Within the event hierarchy, wait events nest within stage events, which nest within statement events, which nest within transaction events.
这些表存储等待事件:These tables store wait events:
events_waits_current:每个线程当前的等待事件。events_waits_current: The current wait event for each thread.events_waits_history:每个线程最近结束的等待事件。events_waits_history: The most recent wait events that have ended per thread.events_waits_history_long:全局(跨所有线程)已结束的最新等待事件。events_waits_history_long: The most recent wait events that have ended globally (across all threads).
下面的部分描述了等待事件表。也有汇总表,用于汇总等待事件的信息;请参见 第 29.12.20.1 节,“等待事件汇总表”。The following sections describe the wait event tables. There are also summary tables that aggregate information about wait events; see Section 29.12.20.1, “Wait Event Summary Tables”.
有关这三张等待事件表之间关系的更多信息,请参见 第 29.9 节,“当前和历史事件的 Performance Schema 表”。For more information about the relationship between the three wait event tables, see Section 29.9, “Performance Schema Tables for Current and Historical Events”.
配置等待事件收集Configuring Wait Event Collection
要控制是否收集等待事件,请设置相关仪器和消费者的状态:To control whether to collect wait events, set the state of the relevant instruments and consumers:
setup_instruments表包含名称以wait开头的仪器。使用这些仪器来启用或禁用各个等待事件类别的收集。Thesetup_instrumentstable contains instruments with names that begin withwait. Use these instruments to enable or disable collection of individual wait event classes.setup_consumers表包含与当前和历史等待事件表名称对应的消费者值。使用这些消费者来筛选等待事件的收集。Thesetup_consumerstable contains consumer values with names corresponding to the current and historical wait event table names. Use these consumers to filter collection of wait events.
一些等待仪器默认启用;其他的默认禁用。例如:Some wait instruments are enabled by default; others are disabled. For example:
mysql>SELECT NAME, ENABLED, TIMEDFROM performance_schema.setup_instrumentsWHERE NAME LIKE 'wait/io/file/innodb%';+-------------------------------------------------+---------+-------+ | NAME | ENABLED | TIMED | +-------------------------------------------------+---------+-------+ | wait/io/file/innodb/innodb_tablespace_open_file | YES | YES | | 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 | | wait/io/file/innodb/innodb_arch_file | YES | YES | | wait/io/file/innodb/innodb_clone_file | YES | YES | +-------------------------------------------------+---------+-------+ mysql>SELECT NAME, ENABLED, TIMEDFROM performance_schema.setup_instrumentsWHERE NAME LIKE 'wait/io/socket/%';+----------------------------------------+---------+-------+ | NAME | ENABLED | TIMED | +----------------------------------------+---------+-------+ | wait/io/socket/sql/server_tcpip_socket | NO | NO | | wait/io/socket/sql/server_unix_socket | NO | NO | | wait/io/socket/sql/client_connection | NO | NO | +----------------------------------------+---------+-------+
等待消费者默认禁用:The wait consumers are disabled by default:
mysql>SELECT *FROM performance_schema.setup_consumersWHERE NAME LIKE 'events_waits%';+---------------------------+---------+ | NAME | ENABLED | +---------------------------+---------+ | events_waits_current | NO | | events_waits_history | NO | | events_waits_history_long | NO | +---------------------------+---------+
要在服务器启动时控制等待事件收集,请在您的 my.cnf 文件中使用如下行:To control wait event collection at server startup, use lines
like these in your my.cnf file:
启用:Enable:
[mysqld] performance-schema-instrument='wait/%=ON' performance-schema-consumer-events-waits-current=ON performance-schema-consumer-events-waits-history=ON performance-schema-consumer-events-waits-history-long=ON
禁用:Disable:
[mysqld] performance-schema-instrument='wait/%=OFF' performance-schema-consumer-events-waits-current=OFF performance-schema-consumer-events-waits-history=OFF performance-schema-consumer-events-waits-history-long=OFF
要在运行时控制等待事件收集,请更新 setup_instruments 和 setup_consumers 表:To control wait event collection at runtime, update the
setup_instruments and
setup_consumers tables:
启用:Enable:
UPDATE performance_schema.setup_instruments SET ENABLED = 'YES', TIMED = 'YES' WHERE NAME LIKE 'wait/%'; UPDATE performance_schema.setup_consumers SET ENABLED = 'YES' WHERE NAME LIKE 'events_waits%';
禁用:Disable:
UPDATE performance_schema.setup_instruments SET ENABLED = 'NO', TIMED = 'NO' WHERE NAME LIKE 'wait/%'; UPDATE performance_schema.setup_consumers SET ENABLED = 'NO' WHERE NAME LIKE 'events_waits%';
要仅收集特定的等待事件,只启用相应的等待工具。要仅收集特定等待事件表的等待事件,启用等待工具,但只启用与所需表对应的等待使用者。To collect only specific wait events, enable only the corresponding wait instruments. To collect wait events only for specific wait event tables, enable the wait instruments but only the wait consumers corresponding to the desired tables.
有关配置事件收集的更多信息,请参见第 29.3 节,“性能模式启动配置”,以及第 29.4 节,“性能模式运行时配置”。For additional information about configuring event collection, see Section 29.3, “Performance Schema Startup Configuration”, and Section 29.4, “Performance Schema Runtime Configuration”.