Rechercher dans le manuel MySQL

26.1 Performance Schema Quick Start

This section briefly introduces the Performance Schema with examples that show how to use it. For additional examples, see Section 26.19, “Using the Performance Schema to Diagnose Problems”.

The Performance Schema is enabled by default. To enable or disable it explicitly, start the server with the performance_schema variable set to an appropriate value. For example, use these lines in the server my.cnf file:

[mysqld]
performance_schema=ON

When the server starts, it sees performance_schema and attempts to initialize the Performance Schema. To verify successful initialization, use this statement:

  1. mysql> SHOW VARIABLES LIKE 'performance_schema';
  2. +--------------------+-------+
  3. | Variable_name      | Value |
  4. +--------------------+-------+
  5. | performance_schema | ON    |
  6. +--------------------+-------+

A value of ON means that the Performance Schema initialized successfully and is ready for use. A value of OFF means that some error occurred. Check the server error log for information about what went wrong.

The Performance Schema is implemented as a storage engine, so you will see it listed in the output from the INFORMATION_SCHEMA.ENGINES table or the SHOW ENGINES statement:

  1. mysql> SELECT * FROM INFORMATION_SCHEMA.ENGINES
  2.        WHERE ENGINE='PERFORMANCE_SCHEMA'\G
  3. *************************** 1. row ***************************
  4.       ENGINE: PERFORMANCE_SCHEMA
  5.      SUPPORT: YES
  6.      COMMENT: Performance Schema
  7.           XA: NO
  8.   SAVEPOINTS: NO
  9.  
  10. mysql> SHOW ENGINES\G
  11. ...
  12.       Engine: PERFORMANCE_SCHEMA
  13.      Support: YES
  14.      Comment: Performance Schema
  15.           XA: NO
  16.   Savepoints: NO
  17. ...

The PERFORMANCE_SCHEMA storage engine operates on tables in the performance_schema database. You can make performance_schema the default database so that references to its tables need not be qualified with the database name:

  1. mysql> USE performance_schema;

Performance Schema tables are stored in the performance_schema database. Information about the structure of this database and its tables can be obtained, as for any other database, by selecting from the INFORMATION_SCHEMA database or by using SHOW statements. For example, use either of these statements to see what Performance Schema tables exist:

  1. mysql> SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
  2.        WHERE TABLE_SCHEMA = 'performance_schema';
  3. +------------------------------------------------------+
  4. | TABLE_NAME                                           |
  5. +------------------------------------------------------+
  6. | accounts                                             |
  7. | cond_instances                                       |
  8. ...
  9. | events_stages_current                                |
  10. | events_stages_history                                |
  11. | events_stages_history_long                           |
  12. | events_stages_summary_by_account_by_event_name       |
  13. | events_stages_summary_by_host_by_event_name          |
  14. | events_stages_summary_by_thread_by_event_name        |
  15. | events_stages_summary_by_user_by_event_name          |
  16. | events_stages_summary_global_by_event_name           |
  17. | events_statements_current                            |
  18. | events_statements_history                            |
  19. | events_statements_history_long                       |
  20. ...
  21. | file_instances                                       |
  22. | file_summary_by_event_name                           |
  23. | file_summary_by_instance                             |
  24. | host_cache                                           |
  25. | hosts                                                |
  26. | memory_summary_by_account_by_event_name              |
  27. | memory_summary_by_host_by_event_name                 |
  28. | memory_summary_by_thread_by_event_name               |
  29. | memory_summary_by_user_by_event_name                 |
  30. | memory_summary_global_by_event_name                  |
  31. | metadata_locks                                       |
  32. | mutex_instances                                      |
  33. | objects_summary_global_by_type                       |
  34. | performance_timers                                   |
  35. | replication_connection_configuration                 |
  36. | replication_connection_status                        |
  37. | replication_applier_configuration                    |
  38. | replication_applier_status                           |
  39. | replication_applier_status_by_coordinator            |
  40. | replication_applier_status_by_worker                 |
  41. | rwlock_instances                                     |
  42. | session_account_connect_attrs                        |
  43. | session_connect_attrs                                |
  44. | setup_actors                                         |
  45. | setup_consumers                                      |
  46. | setup_instruments                                    |
  47. | setup_objects                                        |
  48. | socket_instances                                     |
  49. | socket_summary_by_event_name                         |
  50. | socket_summary_by_instance                           |
  51. | table_handles                                        |
  52. | table_io_waits_summary_by_index_usage                |
  53. | table_io_waits_summary_by_table                      |
  54. | table_lock_waits_summary_by_table                    |
  55. | threads                                              |
  56. | users                                                |
  57. +------------------------------------------------------+
  58.  
  59. mysql> SHOW TABLES FROM performance_schema;
  60. +------------------------------------------------------+
  61. | Tables_in_performance_schema                         |
  62. +------------------------------------------------------+
  63. | accounts                                             |
  64. | cond_instances                                       |
  65. | events_stages_current                                |
  66. | events_stages_history                                |
  67. | events_stages_history_long                           |
  68. ...

The number of Performance Schema tables increases over time as implementation of additional instrumentation proceeds.

The name of the performance_schema database is lowercase, as are the names of tables within it. Queries should specify the names in lowercase.

To see the structure of individual tables, use SHOW CREATE TABLE:

  1. mysql> SHOW CREATE TABLE performance_schema.setup_consumers\G
  2. *************************** 1. row ***************************
  3.        Table: setup_consumers
  4. Create Table: CREATE TABLE `setup_consumers` (
  5.   `NAME` varchar(64) NOT NULL,
  6.   `ENABLED` enum('YES','NO') NOT NULL,
  7.   PRIMARY KEY (`NAME`)
  8. ) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

Table structure is also available by selecting from tables such as INFORMATION_SCHEMA.COLUMNS or by using statements such as SHOW COLUMNS.

Tables in the performance_schema database can be grouped according to the type of information in them: Current events, event histories and summaries, object instances, and setup (configuration) information. The following examples illustrate a few uses for these tables. For detailed information about the tables in each group, see Section 26.12, “Performance Schema Table Descriptions”.

Initially, not all instruments and consumers are enabled, so the performance schema does not collect all events. To turn all of these on and enable event timing, execute two statements (the row counts may differ depending on MySQL version):

  1. mysql> UPDATE performance_schema.setup_instruments
  2.        SET ENABLED = 'YES', TIMED = 'YES';
  3. Query OK, 560 rows affected (0.04 sec)
  4. mysql> UPDATE performance_schema.setup_consumers
  5.        SET ENABLED = 'YES';
  6. Query OK, 10 rows affected (0.00 sec)

To see what the server is doing at the moment, examine the events_waits_current table. It contains one row per thread showing each thread's most recent monitored event:

  1. mysql> SELECT *
  2.        FROM performance_schema.events_waits_current\G
  3. *************************** 1. row ***************************
  4.             THREAD_ID: 0
  5.              EVENT_ID: 5523
  6.          END_EVENT_ID: 5523
  7.            EVENT_NAME: wait/synch/mutex/mysys/THR_LOCK::mutex
  8.                SOURCE: thr_lock.c:525
  9.           TIMER_START: 201660494489586
  10.             TIMER_END: 201660494576112
  11.            TIMER_WAIT: 86526
  12.                 SPINS: NULL
  13.         OBJECT_SCHEMA: NULL
  14.           OBJECT_NAME: NULL
  15.            INDEX_NAME: NULL
  16.           OBJECT_TYPE: NULL
  17. OBJECT_INSTANCE_BEGIN: 142270668
  18.      NESTING_EVENT_ID: NULL
  19.    NESTING_EVENT_TYPE: NULL
  20.             OPERATION: lock
  21.       NUMBER_OF_BYTES: NULL
  22.                 FLAGS: 0
  23. ...

This event indicates that thread 0 was waiting for 86,526 picoseconds to acquire a lock on THR_LOCK::mutex, a mutex in the mysys subsystem. The first few columns provide the following information:

  • The ID columns indicate which thread the event comes from and the event number.

  • EVENT_NAME indicates what was instrumented and SOURCE indicates which source file contains the instrumented code.

  • The timer columns show when the event started and stopped and how long it took. If an event is still in progress, the TIMER_END and TIMER_WAIT values are NULL. Timer values are approximate and expressed in picoseconds. For information about timers and event time collection, see Section 26.4.1, “Performance Schema Event Timing”.

The history tables contain the same kind of rows as the current-events table but have more rows and show what the server has been doing recently rather than currently. The events_waits_history and events_waits_history_long tables contain the most recent 10 events per thread and most recent 10,000 events, respectively. For example, to see information for recent events produced by thread 13, do this:

  1. mysql> SELECT EVENT_ID, EVENT_NAME, TIMER_WAIT
  2.        FROM performance_schema.events_waits_history
  3.        WHERE THREAD_ID = 13
  4.        ORDER BY EVENT_ID;
  5. +----------+-----------------------------------------+------------+
  6. | EVENT_ID | EVENT_NAME                              | TIMER_WAIT |
  7. +----------+-----------------------------------------+------------+
  8. |       86 | wait/synch/mutex/mysys/THR_LOCK::mutex  |     686322 |
  9. |       87 | wait/synch/mutex/mysys/THR_LOCK_malloc  |     320535 |
  10. |       88 | wait/synch/mutex/mysys/THR_LOCK_malloc  |     339390 |
  11. |       89 | wait/synch/mutex/mysys/THR_LOCK_malloc  |     377100 |
  12. |       90 | wait/synch/mutex/sql/LOCK_plugin        |     614673 |
  13. |       91 | wait/synch/mutex/sql/LOCK_open          |     659925 |
  14. |       92 | wait/synch/mutex/sql/THD::LOCK_thd_data |     494001 |
  15. |       93 | wait/synch/mutex/mysys/THR_LOCK_malloc  |     222489 |
  16. |       94 | wait/synch/mutex/mysys/THR_LOCK_malloc  |     214947 |
  17. |       95 | wait/synch/mutex/mysys/LOCK_alarm       |     312993 |
  18. +----------+-----------------------------------------+------------+

As new events are added to a history table, older events are discarded if the table is full.

Summary tables provide aggregated information for all events over time. The tables in this group summarize event data in different ways. To see which instruments have been executed the most times or have taken the most wait time, sort the events_waits_summary_global_by_event_name table on the COUNT_STAR or SUM_TIMER_WAIT column, which correspond to a COUNT(*) or SUM(TIMER_WAIT) value, respectively, calculated over all events:

  1. mysql> SELECT EVENT_NAME, COUNT_STAR
  2.        FROM performance_schema.events_waits_summary_global_by_event_name
  3.        ORDER BY COUNT_STAR DESC LIMIT 10;
  4. +---------------------------------------------------+------------+
  5. | EVENT_NAME                                        | COUNT_STAR |
  6. +---------------------------------------------------+------------+
  7. | wait/synch/mutex/mysys/THR_LOCK_malloc            |       6419 |
  8. | wait/io/file/sql/FRM                              |        452 |
  9. | wait/synch/mutex/sql/LOCK_plugin                  |        337 |
  10. | wait/synch/mutex/mysys/THR_LOCK_open              |        187 |
  11. | wait/synch/mutex/mysys/LOCK_alarm                 |        147 |
  12. | wait/synch/mutex/sql/THD::LOCK_thd_data           |        115 |
  13. | wait/io/file/myisam/kfile                         |        102 |
  14. | wait/synch/mutex/sql/LOCK_global_system_variables |         89 |
  15. | wait/synch/mutex/mysys/THR_LOCK::mutex            |         89 |
  16. | wait/synch/mutex/sql/LOCK_open                    |         88 |
  17. +---------------------------------------------------+------------+
  18.  
  19. mysql> SELECT EVENT_NAME, SUM_TIMER_WAIT
  20.        FROM performance_schema.events_waits_summary_global_by_event_name
  21.        ORDER BY SUM_TIMER_WAIT DESC LIMIT 10;
  22. +----------------------------------------+----------------+
  23. | EVENT_NAME                             | SUM_TIMER_WAIT |
  24. +----------------------------------------+----------------+
  25. | wait/io/file/sql/MYSQL_LOG             |     1599816582 |
  26. | wait/synch/mutex/mysys/THR_LOCK_malloc |     1530083250 |
  27. | wait/io/file/sql/binlog_index          |     1385291934 |
  28. | wait/io/file/sql/FRM                   |     1292823243 |
  29. | wait/io/file/myisam/kfile              |      411193611 |
  30. | wait/io/file/myisam/dfile              |      322401645 |
  31. | wait/synch/mutex/mysys/LOCK_alarm      |      145126935 |
  32. | wait/io/file/sql/casetest              |      104324715 |
  33. | wait/synch/mutex/sql/LOCK_plugin       |       86027823 |
  34. | wait/io/file/sql/pid                   |       72591750 |
  35. +----------------------------------------+----------------+

These results show that the THR_LOCK_malloc mutex is hot, both in terms of how often it is used and amount of time that threads wait attempting to acquire it.

Note

The THR_LOCK_malloc mutex is used only in debug builds. In production builds it is not hot because it is nonexistent.

Instance tables document what types of objects are instrumented. An instrumented object, when used by the server, produces an event. These tables provide event names and explanatory notes or status information. For example, the file_instances table lists instances of instruments for file I/O operations and their associated files:

  1. mysql> SELECT *
  2.        FROM performance_schema.file_instances\G
  3. *************************** 1. row ***************************
  4.  FILE_NAME: /opt/mysql-log/60500/binlog.000007
  5. EVENT_NAME: wait/io/file/sql/binlog
  6. OPEN_COUNT: 0
  7. *************************** 2. row ***************************
  8.  FILE_NAME: /opt/mysql/60500/data/mysql/tables_priv.MYI
  9. EVENT_NAME: wait/io/file/myisam/kfile
  10. OPEN_COUNT: 1
  11. *************************** 3. row ***************************
  12.  FILE_NAME: /opt/mysql/60500/data/mysql/columns_priv.MYI
  13. EVENT_NAME: wait/io/file/myisam/kfile
  14. OPEN_COUNT: 1
  15. ...

Setup tables are used to configure and display monitoring characteristics. For example, setup_instruments lists the set of instruments for which events can be collected and shows which of them are enabled:

  1. mysql> SELECT NAME, ENABLED, TIMED
  2.        FROM performance_schema.setup_instruments;
  3. +---------------------------------------------------+---------+-------+
  4. | NAME                                              | ENABLED | TIMED |
  5. +---------------------------------------------------+---------+-------+
  6. ...
  7. | stage/sql/end                                     | NO      | NO    |
  8. | stage/sql/executing                               | NO      | NO    |
  9. | stage/sql/init                                    | NO      | NO    |
  10. | stage/sql/insert                                  | NO      | NO    |
  11. ...
  12. | statement/sql/load                                | YES     | YES   |
  13. | statement/sql/grant                               | YES     | YES   |
  14. | statement/sql/check                               | YES     | YES   |
  15. | statement/sql/flush                               | YES     | YES   |
  16. ...
  17. | wait/synch/mutex/sql/LOCK_global_read_lock        | YES     | YES   |
  18. | wait/synch/mutex/sql/LOCK_global_system_variables | YES     | YES   |
  19. | wait/synch/mutex/sql/LOCK_lock_db                 | YES     | YES   |
  20. | wait/synch/mutex/sql/LOCK_manager                 | YES     | YES   |
  21. ...
  22. | wait/synch/rwlock/sql/LOCK_grant                  | YES     | YES   |
  23. | wait/synch/rwlock/sql/LOGGER::LOCK_logger         | YES     | YES   |
  24. | wait/synch/rwlock/sql/LOCK_sys_init_connect       | YES     | YES   |
  25. | wait/synch/rwlock/sql/LOCK_sys_init_slave         | YES     | YES   |
  26. ...
  27. | wait/io/file/sql/binlog                           | YES     | YES   |
  28. | wait/io/file/sql/binlog_index                     | YES     | YES   |
  29. | wait/io/file/sql/casetest                         | YES     | YES   |
  30. | wait/io/file/sql/dbopt                            | YES     | YES   |
  31. ...

To understand how to interpret instrument names, see Section 26.6, “Performance Schema Instrument Naming Conventions”.

To control whether events are collected for an instrument, set its ENABLED value to YES or NO. For example:

  1. mysql> UPDATE performance_schema.setup_instruments
  2.        SET ENABLED = 'NO'
  3.        WHERE NAME = 'wait/synch/mutex/sql/LOCK_mysql_create_db';

The Performance Schema uses collected events to update tables in the performance_schema database, which act as consumers of event information. The setup_consumers table lists the available consumers and which are enabled:

  1. mysql> SELECT * FROM performance_schema.setup_consumers;
  2. +----------------------------------+---------+
  3. | NAME                             | ENABLED |
  4. +----------------------------------+---------+
  5. | events_stages_current            | NO      |
  6. | events_stages_history            | NO      |
  7. | events_stages_history_long       | NO      |
  8. | events_statements_current        | YES     |
  9. | events_statements_history        | YES     |
  10. | events_statements_history_long   | NO      |
  11. | events_transactions_current      | YES     |
  12. | events_transactions_history      | YES     |
  13. | events_transactions_history_long | NO      |
  14. | events_waits_current             | NO      |
  15. | events_waits_history             | NO      |
  16. | events_waits_history_long        | NO      |
  17. | global_instrumentation           | YES     |
  18. | thread_instrumentation           | YES     |
  19. | statements_digest                | YES     |
  20. +----------------------------------+---------+

To control whether the Performance Schema maintains a consumer as a destination for event information, set its ENABLED value.

For more information about the setup tables and how to use them to control event collection, see Section 26.4.2, “Performance Schema Event Filtering”.

There are some miscellaneous tables that do not fall into any of the previous groups. For example, performance_timers lists the available event timers and their characteristics. For information about timers, see Section 26.4.1, “Performance Schema Event Timing”.


Suchen Sie im MySQL-Handbuch

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 26/06/2006, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/mysql-rf-performance-schema-quick-start

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.

Referenzen

  1. Zeigen Sie - html-Dokument Sprache des Dokuments:en Manuel MySQL : https://dev.mysql.com/

Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.

Inhaltsverzeichnis Haut