MySql 中文参考指南

Chapter 29 MySQL Performance Schema

目录

Table of Contents

MySQL 性能模式是一项用于低级别监控 MySQL 服务器执行的功能。性能模式具有以下特性:

The MySQL Performance Schema is a feature for monitoring MySQL Server execution at a low level. The Performance Schema has these characteristics:

  1. The Performance Schema provides a way to inspect internal execution of the server at runtime. It is implemented using the PERFORMANCE_SCHEMA storage engine and the performance_schema database. The Performance Schema focuses primarily on performance data. This differs from INFORMATION_SCHEMA, which serves for inspection of metadata.

  2. The Performance Schema monitors server events. An “event” is anything the server does that takes time and has been instrumented so that timing information can be collected. In general, an event could be a function call, a wait for the operating system, a stage of an SQL statement execution such as parsing or sorting, or an entire statement or group of statements. Event collection provides access to information about synchronization calls (such as for mutexes) file and table I/O, table locks, and so forth for the server and for several storage engines.

  3. Performance Schema events are distinct from events written to the server’s binary log (which describe data modifications) and Event Scheduler events (which are a type of stored program).

  4. Performance Schema events are specific to a given instance of the MySQL Server. Performance Schema tables are considered local to the server, and changes to them are not replicated or written to the binary log.

  5. Current events are available, as well as event histories and summaries. This enables you to determine how many times instrumented activities were performed and how much time they took. Event information is available to show the activities of specific threads, or activity associated with particular objects such as a mutex or file.

  6. The PERFORMANCE_SCHEMA storage engine collects event data using “instrumentation points” in server source code.

  7. Collected events are stored in tables in the performance_schema database. These tables can be queried using SELECT statements like other tables.

  8. Performance Schema configuration can be modified dynamically by updating tables in the performance_schema database through SQL statements. Configuration changes affect data collection immediately.

  9. Tables in the Performance Schema are in-memory tables that use no persistent on-disk storage. The contents are repopulated beginning at server startup and discarded at server shutdown.

  10. Monitoring is available on all platforms supported by MySQL.

可能适用于某些限制:不同平台的计时器类型可能有所不同。适用于存储引擎的检测器可能并未针对所有存储引擎实现。第三方引擎的检测由引擎维护者负责。另请参见 Section 29.20, “Restrictions on Performance Schema”

Some limitations might apply: The types of timers might vary per platform. Instruments that apply to storage engines might not be implemented for all storage engines. Instrumentation of each third-party engine is the responsibility of the engine maintainer. See also Section 29.20, “Restrictions on Performance Schema”.

  1. Data collection is implemented by modifying the server source code to add instrumentation. There are no separate threads associated with the Performance Schema, unlike other features such as replication or the Event Scheduler.

性能模式旨在提供有关服务器执行的有用信息,同时对服务器性能的影响最小。该实现遵循以下设计目标:

The Performance Schema is intended to provide access to useful information about server execution while having minimal impact on server performance. The implementation follows these design goals:

  1. Activating the Performance Schema causes no changes in server behavior. For example, it does not cause thread scheduling to change, and it does not cause query execution plans (as shown by EXPLAIN) to change.

  2. Server monitoring occurs continuously and unobtrusively with very little overhead. Activating the Performance Schema does not make the server unusable.

  3. The parser is unchanged. There are no new keywords or statements.

  4. Execution of server code proceeds normally even if the Performance Schema fails internally.

  5. When there is a choice between performing processing during event collection initially or during event retrieval later, priority is given to making collection faster. This is because collection is ongoing whereas retrieval is on demand and might never happen at all.

  6. Most Performance Schema tables have indexes, which gives the optimizer access to execution plans other than full table scans. For more information, see Section 10.2.4, “Optimizing Performance Schema Queries”.

  7. It is easy to add new instrumentation points.

  8. Instrumentation is versioned. If the instrumentation implementation changes, previously instrumented code continues to work. This benefits developers of third-party plugins because it is not necessary to upgrade each plugin to stay synchronized with the latest Performance Schema changes.

MySQL sys 模式是一组对象,可以通过这些对象方便地访问 Performance Schema 收集的数据。sys 模式默认安装。有关使用方法的说明,请参阅 第 30 章,MySQL sys 模式

The MySQL _sys_ schema is a set of objects that provides convenient access to data collected by the Performance Schema. The _sys_ schema is installed by default. For usage instructions, see link:sys-schema.html[Chapter 30, MySQL sys Schema].