25.4 Performance Schema Runtime Configuration

Specific Performance Schema features can be enabled at runtime to control which types of event collection occur.

Performance Schema setup tables contain information about monitoring configuration:

 mysql> SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
        WHERE TABLE_SCHEMA = 'performance_schema'
        AND TABLE_NAME LIKE 'setup%';
 +-------------------+
 | TABLE_NAME        |
 +-------------------+
 | setup_actors      |
 | setup_consumers   |
 | setup_instruments |
 | setup_objects     |
 | setup_timers      |
 +-------------------+

You can examine the contents of these tables to obtain information about Performance Schema monitoring characteristics. If you have the 'UPDATE' privilege, you can change Performance Schema operation by modifying setup tables to affect how monitoring occurs. For additional details about these tables, see *note performance-schema-setup-tables::.

To see which event timers are selected, query the *note 'setup_timers': performance-schema-setup-timers-table. tables:

 mysql> SELECT * FROM performance_schema.setup_timers;
 +-------------+-------------+
 | NAME        | TIMER_NAME  |
 +-------------+-------------+
 | idle        | MICROSECOND |
 | wait        | CYCLE       |
 | stage       | NANOSECOND  |
 | statement   | NANOSECOND  |
 | transaction | NANOSECOND  |
 +-------------+-------------+

The 'NAME' value indicates the type of instrument to which the timer applies, and 'TIMER_NAME' indicates which timer applies to those instruments. The timer applies to instruments where their name begins with an element matching the 'NAME' value.

To change the timer, update the 'NAME' value. For example, to use the 'NANOSECOND' timer for the 'wait' timer:

 mysql> UPDATE performance_schema.setup_timers
        SET TIMER_NAME = 'NANOSECOND'
        WHERE NAME = 'wait';
 mysql> SELECT * FROM performance_schema.setup_timers;
 +-------------+-------------+
 | NAME        | TIMER_NAME  |
 +-------------+-------------+
 | idle        | MICROSECOND |
 | wait        | NANOSECOND  |
 | stage       | NANOSECOND  |
 | statement   | NANOSECOND  |
 | transaction | NANOSECOND  |
 +-------------+-------------+

For discussion of timers, see *note performance-schema-timing::.

The note 'setup_instruments': performance-schema-setup-instruments-table. and note 'setup_consumers': performance-schema-setup-consumers-table. tables list the instruments for which events can be collected and the types of consumers for which event information actually is collected, respectively. Other setup tables enable further modification of the monitoring configuration. *note performance-schema-filtering::, discusses how you can modify these tables to affect event collection.

If there are Performance Schema configuration changes that must be made at runtime using SQL statements and you would like these changes to take effect each time the server starts, put the statements in a file and start the server with the 'init_file' system variable set to name the file. This strategy can also be useful if you have multiple monitoring configurations, each tailored to produce a different kind of monitoring, such as casual server health monitoring, incident investigation, application behavior troubleshooting, and so forth. Put the statements for each monitoring configuration into their own file and specify the appropriate file as the 'init_file' value when you start the server.

 File: manual.info.tmp, Node: performance-schema-timing, Next: performance-schema-filtering, Prev: performance-schema-runtime-configuration, Up: performance-schema-runtime-configuration

25.4.1 Performance Schema Event Timing

Events are collected by means of instrumentation added to the server source code. Instruments time events, which is how the Performance Schema provides an idea of how long events take. It is also possible to configure instruments not to collect timing information. This section discusses the available timers and their characteristics, and how timing values are represented in events.

Performance Schema Timers

Two Performance Schema tables provide timer information:

Each timer row in note 'setup_timers': performance-schema-setup-timers-table. must refer to one of the timers listed in note 'performance_timers': performance-schema-performance-timers-table.

Timers vary in precision and amount of overhead. To see what timers are available and their characteristics, check the *note 'performance_timers': performance-schema-performance-timers-table. table:

 mysql> SELECT * FROM performance_schema.performance_timers;
 +-------------+-----------------+------------------+----------------+
 | TIMER_NAME  | TIMER_FREQUENCY | TIMER_RESOLUTION | TIMER_OVERHEAD |
 +-------------+-----------------+------------------+----------------+
 | CYCLE       |      2389029850 |                1 |             72 |
 | NANOSECOND  |      1000000000 |                1 |            112 |
 | MICROSECOND |         1000000 |                1 |            136 |
 | MILLISECOND |            1036 |                1 |            168 |
 | TICK        |             105 |                1 |           2416 |
 +-------------+-----------------+------------------+----------------+

If the values associated with a given timer name are 'NULL', that timer is not supported on your platform. The rows that do not contain 'NULL' indicate which timers you can use in *note 'setup_timers': performance-schema-setup-timers-table.

The columns have these meanings:

To see which timers are in effect or to change timers, access the *note 'setup_timers': performance-schema-setup-timers-table. table:

 mysql> SELECT * FROM performance_schema.setup_timers;
 +-------------+-------------+
 | NAME        | TIMER_NAME  |
 +-------------+-------------+
 | idle        | MICROSECOND |
 | wait        | CYCLE       |
 | stage       | NANOSECOND  |
 | statement   | NANOSECOND  |
 | transaction | NANOSECOND  |
 +-------------+-------------+

 mysql> UPDATE performance_schema.setup_timers
        SET TIMER_NAME = 'MICROSECOND'
        WHERE NAME = 'idle';
 mysql> SELECT * FROM performance_schema.setup_timers;
 +-------------+-------------+
 | NAME        | TIMER_NAME  |
 +-------------+-------------+
 | idle        | MICROSECOND |
 | wait        | CYCLE       |
 | stage       | NANOSECOND  |
 | statement   | NANOSECOND  |
 | transaction | NANOSECOND  |
 +-------------+-------------+

By default, the Performance Schema uses the best timer available for each instrument type, but you can select a different one.

To time wait events, the most important criterion is to reduce overhead, at the possible expense of the timer accuracy, so using the 'CYCLE' timer is the best.

The time a statement (or stage) takes to execute is in general orders of magnitude larger than the time it takes to execute a single wait. To time statements, the most important criterion is to have an accurate measure, which is not affected by changes in processor frequency, so using a timer which is not based on cycles is the best. The default timer for statements is 'NANOSECOND'. The extra 'overhead' compared to the 'CYCLE' timer is not significant, because the overhead caused by calling a timer twice (once when the statement starts, once when it ends) is orders of magnitude less compared to the CPU time used to execute the statement itself. Using the 'CYCLE' timer has no benefit here, only drawbacks.

The precision offered by the cycle counter depends on processor speed. If the processor runs at 1 GHz (one billion cycles/second) or higher, the cycle counter delivers sub-nanosecond precision. Using the cycle counter is much cheaper than getting the actual time of day. For example, the standard 'gettimeofday()' function can take hundreds of cycles, which is an unacceptable overhead for data gathering that may occur thousands or millions of times per second.

Cycle counters also have disadvantages:

MySQL works with cycle counters on x386 (Windows, macOS, Linux, Solaris, and other Unix flavors), PowerPC, and IA-64.

Performance Schema Timer Representation in Events

Rows in Performance Schema tables that store current events and historical events have three columns to represent timing information: 'TIMER_START' and 'TIMER_END' indicate when an event started and finished, and 'TIMER_WAIT' indicates event duration.

The *note 'setup_instruments': performance-schema-setup-instruments-table. table has an 'ENABLED' column to indicate the instruments for which to collect events. The table also has a 'TIMED' column to indicate which instruments are timed. If an instrument is not enabled, it produces no events. If an enabled instrument is not timed, events produced by the instrument have 'NULL' for the 'TIMER_START', 'TIMER_END', and 'TIMER_WAIT' timer values. This in turn causes those values to be ignored when calculating aggregate time values in summary tables (sum, minimum, maximum, and average).

Internally, times within events are stored in units given by the timer in effect when event timing begins. For display when events are retrieved from Performance Schema tables, times are shown in picoseconds (trillionths of a second) to normalize them to a standard unit, regardless of which timer is selected.

Modifications to the note 'setup_timers': performance-schema-setup-timers-table. table affect monitoring immediately. Events already in progress may use the original timer for the begin time and the new timer for the end time. To avoid unpredictable results after you make timer changes, use note 'TRUNCATE TABLE': truncate-table. to reset Performance Schema statistics.

The timer baseline ('time zero') occurs at Performance Schema initialization during server startup. 'TIMER_START' and 'TIMER_END' values in events represent picoseconds since the baseline. 'TIMER_WAIT' values are durations in picoseconds.

Picosecond values in events are approximate. Their accuracy is subject to the usual forms of error associated with conversion from one unit to another. If the 'CYCLE' timer is used and the processor rate varies, there might be drift. For these reasons, it is not reasonable to look at the 'TIMER_START' value for an event as an accurate measure of time elapsed since server startup. On the other hand, it is reasonable to use 'TIMER_START' or 'TIMER_WAIT' values in 'ORDER BY' clauses to order events by start time or duration.

The choice of picoseconds in events rather than a value such as microseconds has a performance basis. One implementation goal was to show results in a uniform time unit, regardless of the timer. In an ideal world this time unit would look like a wall-clock unit and be reasonably precise; in other words, microseconds. But to convert cycles or nanoseconds to microseconds, it would be necessary to perform a division for every instrumentation. Division is expensive on many platforms. Multiplication is not expensive, so that is what is used. Therefore, the time unit is an integer multiple of the highest possible 'TIMER_FREQUENCY' value, using a multiplier large enough to ensure that there is no major precision loss. The result is that the time unit is 'picoseconds.' This precision is spurious, but the decision enables overhead to be minimized.

While a wait, stage, statement, or transaction event is executing, the respective current-event tables display current-event timing information:

 events_waits_current
 events_stages_current
 events_statements_current
 events_transactions_current

To make it possible to determine how long a not-yet-completed event has been running, the timer columns are set as follows:

Events that have not yet completed have an 'END_EVENT_ID' value of 'NULL'. To assess time elapsed so far for an event, use the 'TIMER_WAIT' column. Therefore, to identify events that have not yet completed and have taken longer than N picoseconds thus far, monitoring applications can use this expression in queries:

 WHERE END_EVENT_ID IS NULL AND TIMER_WAIT > N

Event identification as just described assumes that the corresponding instruments have 'ENABLED' and 'TIMED' set to 'YES' and that the relevant consumers are enabled.

 File: manual.info.tmp, Node: performance-schema-filtering, Next: performance-schema-pre-filtering, Prev: performance-schema-timing, Up: performance-schema-runtime-configuration

25.4.2 Performance Schema Event Filtering

Events are processed in a producer/consumer fashion:

Filtering can be done at different stages of performance monitoring:

The following sections provide more detail about pre-filtering and provide guidelines for naming instruments or consumers in filtering operations. For information about writing queries to retrieve information (post-filtering), see *note performance-schema-queries::.

 File: manual.info.tmp, Node: performance-schema-pre-filtering, Next: performance-schema-instrument-filtering, Prev: performance-schema-filtering, Up: performance-schema-runtime-configuration

25.4.3 Event Pre-Filtering

Pre-filtering is done by the Performance Schema and has a global effect that applies to all users. Pre-filtering can be applied to either the producer or consumer stage of event processing:

Modifications to any of these tables affect monitoring immediately, with some exceptions:

When you change the monitoring configuration, the Performance Schema does not flush the history tables. Events already collected remain in the current-events and history tables until displaced by newer events. If you disable instruments, you might need to wait a while before events for them are displaced by newer events of interest. Alternatively, use *note 'TRUNCATE TABLE': truncate-table. to empty the history tables.

After making instrumentation changes, you might want to truncate the summary tables. Generally, the effect is to reset the summary columns to 0 or 'NULL', not to remove rows. This enables you to clear collected values and restart aggregation. That might be useful, for example, after you have made a runtime configuration change. Exceptions to this truncation behavior are noted in individual summary table sections.

The following sections describe how to use specific tables to control Performance Schema pre-filtering.

 File: manual.info.tmp, Node: performance-schema-instrument-filtering, Next: performance-schema-object-filtering, Prev: performance-schema-pre-filtering, Up: performance-schema-runtime-configuration

25.4.4 Pre-Filtering by Instrument

The *note 'setup_instruments': performance-schema-setup-instruments-table. table lists the available instruments:

 mysql> SELECT * FROM performance_schema.setup_instruments;
 +---------------------------------------------------+---------+-------+
 | NAME                                              | ENABLED | TIMED |
 +---------------------------------------------------+---------+-------+
 ...
 | stage/sql/end                                     | NO      | NO    |
 | stage/sql/executing                               | NO      | NO    |
 | stage/sql/init                                    | NO      | NO    |
 | stage/sql/insert                                  | NO      | NO    |
 ...
 | statement/sql/load                                | YES     | YES   |
 | statement/sql/grant                               | YES     | YES   |
 | statement/sql/check                               | YES     | YES   |
 | statement/sql/flush                               | YES     | YES   |
 ...
 | wait/synch/mutex/sql/LOCK_global_read_lock        | YES     | YES   |
 | wait/synch/mutex/sql/LOCK_global_system_variables | YES     | YES   |
 | wait/synch/mutex/sql/LOCK_lock_db                 | YES     | YES   |
 | wait/synch/mutex/sql/LOCK_manager                 | YES     | YES   |
 ...
 | wait/synch/rwlock/sql/LOCK_grant                  | YES     | YES   |
 | wait/synch/rwlock/sql/LOGGER::LOCK_logger         | YES     | YES   |
 | wait/synch/rwlock/sql/LOCK_sys_init_connect       | YES     | YES   |
 | wait/synch/rwlock/sql/LOCK_sys_init_slave         | YES     | YES   |
 ...
 | wait/io/file/sql/binlog                           | YES     | YES   |
 | wait/io/file/sql/binlog_index                     | YES     | YES   |
 | wait/io/file/sql/casetest                         | YES     | YES   |
 | wait/io/file/sql/dbopt                            | YES     | YES   |
 ...

To control whether an instrument is enabled, set its 'ENABLED' column to 'YES' or 'NO'. To configure whether to collect timing information for an enabled instrument, set its 'TIMED' value to 'YES' or 'NO'. Setting the 'TIMED' column affects Performance Schema table contents as described in *note performance-schema-timing::.

Modifications to most *note 'setup_instruments': performance-schema-setup-instruments-table. rows affect monitoring immediately. For some instruments, modifications are effective only at server startup; changing them at runtime has no effect. This affects primarily mutexes, conditions, and rwlocks in the server, although there may be other instruments for which this is true.

The note 'setup_instruments': performance-schema-setup-instruments-table. table provides the most basic form of control over event production. To further refine event production based on the type of object or thread being monitored, other tables may be used as described in note performance-schema-pre-filtering::.

The following examples demonstrate possible operations on the note 'setup_instruments': performance-schema-setup-instruments-table. table. These changes, like other pre-filtering operations, affect all users. Some of these queries use the 'LIKE' operator and a pattern match instrument names. For additional information about specifying patterns to select instruments, see note performance-schema-filtering-names::.

 File: manual.info.tmp, Node: performance-schema-object-filtering, Next: performance-schema-thread-filtering, Prev: performance-schema-instrument-filtering, Up: performance-schema-runtime-configuration

25.4.5 Pre-Filtering by Object

The note 'setup_objects': performance-schema-setup-objects-table. table controls whether the Performance Schema monitors particular table and stored program objects. The initial note 'setup_objects': performance-schema-setup-objects-table. contents look like this:

 mysql> SELECT * FROM performance_schema.setup_objects;
 +-------------+--------------------+-------------+---------+-------+
 | OBJECT_TYPE | OBJECT_SCHEMA      | OBJECT_NAME | ENABLED | TIMED |
 +-------------+--------------------+-------------+---------+-------+
 | EVENT       | mysql              | %           | NO      | NO    |
 | EVENT       | performance_schema | %           | NO      | NO    |
 | EVENT       | information_schema | %           | NO      | NO    |
 | EVENT       | %                  | %           | YES     | YES   |
 | FUNCTION    | mysql              | %           | NO      | NO    |
 | FUNCTION    | performance_schema | %           | NO      | NO    |
 | FUNCTION    | information_schema | %           | NO      | NO    |
 | FUNCTION    | %                  | %           | YES     | YES   |
 | PROCEDURE   | mysql              | %           | NO      | NO    |
 | PROCEDURE   | performance_schema | %           | NO      | NO    |
 | PROCEDURE   | information_schema | %           | NO      | NO    |
 | PROCEDURE   | %                  | %           | YES     | YES   |
 | TABLE       | mysql              | %           | NO      | NO    |
 | TABLE       | performance_schema | %           | NO      | NO    |
 | TABLE       | information_schema | %           | NO      | NO    |
 | TABLE       | %                  | %           | YES     | YES   |
 | TRIGGER     | mysql              | %           | NO      | NO    |
 | TRIGGER     | performance_schema | %           | NO      | NO    |
 | TRIGGER     | information_schema | %           | NO      | NO    |
 | TRIGGER     | %                  | %           | YES     | YES   |
 +-------------+--------------------+-------------+---------+-------+

Modifications to the *note 'setup_objects': performance-schema-setup-objects-table. table affect object monitoring immediately.

The 'OBJECT_TYPE' column indicates the type of object to which a row applies. 'TABLE' filtering affects table I/O events ('wait/io/table/sql/handler' instrument) and table lock events ('wait/lock/table/sql/handler' instrument).

The 'OBJECT_SCHEMA' and 'OBJECT_NAME' columns should contain a literal schema or object name, or ''%'' to match any name.

The 'ENABLED' column indicates whether matching objects are monitored, and 'TIMED' indicates whether to collect timing information. Setting the 'TIMED' column affects Performance Schema table contents as described in *note performance-schema-timing::.

The effect of the default object configuration is to instrument all objects except those in the 'mysql', 'INFORMATION_SCHEMA', and 'performance_schema' databases. (Tables in the 'INFORMATION_SCHEMA' database are not instrumented regardless of the contents of *note 'setup_objects': performance-schema-setup-objects-table.; the row for 'information_schema.%' simply makes this default explicit.)

When the Performance Schema checks for a match in *note 'setup_objects': performance-schema-setup-objects-table, it tries to find more specific matches first. For rows that match a given 'OBJECT_TYPE', the Performance Schema checks rows in this order:

For example, with a table 'db1.t1', the Performance Schema looks in 'TABLE' rows for a match for ''db1'' and ''t1'', then for ''db1'' and ''%'', then for ''%'' and ''%''. The order in which matching occurs matters because different matching *note 'setup_objects': performance-schema-setup-objects-table. rows can have different 'ENABLED' and 'TIMED' values.

For table-related events, the Performance Schema combines the contents of note 'setup_objects': performance-schema-setup-objects-table. with note 'setup_instruments': performance-schema-setup-instruments-table. to determine whether to enable instruments and whether to time enabled instruments:

For stored program objects, the Performance Schema takes the 'ENABLED' and 'TIMED' columns directly from the note 'setup_objects': performance-schema-setup-objects-table. row. There is no combining of values with note 'setup_instruments': performance-schema-setup-instruments-table.

Suppose that *note 'setup_objects': performance-schema-setup-objects-table. contains the following 'TABLE' rows that apply to 'db1', 'db2', and 'db3':

 +-------------+---------------+-------------+---------+-------+
 | OBJECT_TYPE | OBJECT_SCHEMA | OBJECT_NAME | ENABLED | TIMED |
 +-------------+---------------+-------------+---------+-------+
 | TABLE       | db1           | t1          | YES     | YES   |
 | TABLE       | db1           | t2          | NO      | NO    |
 | TABLE       | db2           | %           | YES     | YES   |
 | TABLE       | db3           | %           | NO      | NO    |
 | TABLE       | %             | %           | YES     | YES   |
 +-------------+---------------+-------------+---------+-------+

If an object-related instrument in note 'setup_instruments': performance-schema-setup-instruments-table. has an 'ENABLED' value of 'NO', events for the object are not monitored. If the 'ENABLED' value is 'YES', event monitoring occurs according to the 'ENABLED' value in the relevant note 'setup_objects': performance-schema-setup-objects-table. row:

Similar logic applies for combining the 'TIMED' columns from the note 'setup_instruments': performance-schema-setup-instruments-table. and note 'setup_objects': performance-schema-setup-objects-table. tables to determine whether to collect event timing information.

If a persistent table and a temporary table have the same name, matching against *note 'setup_objects': performance-schema-setup-objects-table. rows occurs the same way for both. It is not possible to enable monitoring for one table but not the other. However, each table is instrumented separately.

 File: manual.info.tmp, Node: performance-schema-thread-filtering, Next: performance-schema-consumer-filtering, Prev: performance-schema-object-filtering, Up: performance-schema-runtime-configuration

25.4.6 Pre-Filtering by Thread

The *note 'threads': performance-schema-threads-table. table contains a row for each server thread. Each row contains information about a thread and indicates whether monitoring is enabled for it. For the Performance Schema to monitor a thread, these things must be true:

The *note 'threads': performance-schema-threads-table. table also indicates for each server thread whether to perform historical event logging. This includes wait, stage, statement, and transaction events and affects logging to these tables:

 events_waits_history
 events_waits_history_long
 events_stages_history
 events_stages_history_long
 events_statements_history
 events_statements_history_long
 events_transactions_history
 events_transactions_history_long

For historical event logging to occur, these things must be true:

For foreground threads (resulting from client connections), the initial values of the 'INSTRUMENTED' and 'HISTORY' columns in note 'threads': performance-schema-threads-table. table rows are determined by whether the user account associated with a thread matches any row in the note 'setup_actors': performance-schema-setup-actors-table. table. The values come from the 'ENABLED' and 'HISTORY' columns of the matching *note 'setup_actors': performance-schema-setup-actors-table. table row.

For background threads, there is no associated user. 'INSTRUMENTED' and 'HISTORY' are 'YES' by default and *note 'setup_actors': performance-schema-setup-actors-table. is not consulted.

The initial *note 'setup_actors': performance-schema-setup-actors-table. contents look like this:

 mysql> SELECT * FROM performance_schema.setup_actors;
 +------+------+------+---------+---------+
 | HOST | USER | ROLE | ENABLED | HISTORY |
 +------+------+------+---------+---------+
 | %    | %    | %    | YES     | YES     |
 +------+------+------+---------+---------+

The 'HOST' and 'USER' columns should contain a literal host or user name, or ''%'' to match any name.

The 'ENABLED' and 'HISTORY' columns indicate whether to enable instrumentation and historical event logging for matching threads, subject to the other conditions described previously.

When the Performance Schema checks for a match for each new foreground thread in 'setup_actors', it tries to find more specific matches first, using the 'USER' and 'HOST' columns ('ROLE' is unused):

The order in which matching occurs matters because different matching *note 'setup_actors': performance-schema-setup-actors-table. rows can have different 'USER' and 'HOST' values. This enables instrumenting and historical event logging to be applied selectively per host, user, or account (user and host combination), based on the 'ENABLED' and 'HISTORY' column values:

The 'ENABLED' and 'HISTORY' columns in *note 'setup_actors': performance-schema-setup-actors-table. rows can be set to 'YES' or 'NO' independent of one another. This means you can enable instrumentation separately from whether you collect historical events.

By default, monitoring and historical event collection are enabled for all new foreground threads because the *note 'setup_actors': performance-schema-setup-actors-table. table initially contains a row with ''%'' for both 'HOST' and 'USER'. To perform more limited matching such as to enable monitoring only for some foreground threads, you must change this row because it matches any connection, and add rows for more specific 'HOST'/'USER' combinations.

Suppose that you modify *note 'setup_actors': performance-schema-setup-actors-table. as follows:

 UPDATE performance_schema.setup_actors
 SET ENABLED = 'NO', HISTORY = 'NO'
 WHERE HOST = '%' AND USER = '%';
 INSERT INTO performance_schema.setup_actors
 (HOST,USER,ROLE,ENABLED,HISTORY)
 VALUES('localhost','joe','%','YES','YES');
 INSERT INTO performance_schema.setup_actors
 (HOST,USER,ROLE,ENABLED,HISTORY)
 VALUES('hosta.example.com','joe','%','YES','NO');
 INSERT INTO performance_schema.setup_actors
 (HOST,USER,ROLE,ENABLED,HISTORY)
 VALUES('%','sam','%','NO','YES');

The note 'UPDATE': update. statement changes the default match to disable instrumentation and historical event collection. The note 'INSERT': insert. statements add rows for more specific matches.

Now the Performance Schema determines how to set the 'INSTRUMENTED' and 'HISTORY' values for new connection threads as follows:

Modifications to the note 'setup_actors': performance-schema-setup-actors-table. table affect only foreground threads created subsequent to the modification, not existing threads. To affect existing threads, modify the 'INSTRUMENTED' and 'HISTORY' columns of note 'threads': performance-schema-threads-table. table rows.

 File: manual.info.tmp, Node: performance-schema-consumer-filtering, Next: performance-schema-consumer-configurations, Prev: performance-schema-thread-filtering, Up: performance-schema-runtime-configuration

25.4.7 Pre-Filtering by Consumer

The *note 'setup_consumers': performance-schema-setup-consumers-table. table lists the available consumer types and which are enabled:

 mysql> SELECT * FROM performance_schema.setup_consumers;
 +----------------------------------+---------+
 | NAME                             | ENABLED |
 +----------------------------------+---------+
 | events_stages_current            | NO      |
 | events_stages_history            | NO      |
 | events_stages_history_long       | NO      |
 | events_statements_current        | YES     |
 | events_statements_history        | YES     |
 | events_statements_history_long   | NO      |
 | events_transactions_current      | NO      |
 | events_transactions_history      | NO      |
 | events_transactions_history_long | NO      |
 | events_waits_current             | NO      |
 | events_waits_history             | NO      |
 | events_waits_history_long        | NO      |
 | global_instrumentation           | YES     |
 | thread_instrumentation           | YES     |
 | statements_digest                | YES     |
 +----------------------------------+---------+

Modify the *note 'setup_consumers': performance-schema-setup-consumers-table. table to affect pre-filtering at the consumer stage and determine the destinations to which events are sent. To enable or disable a consumer, set its 'ENABLED' value to 'YES' or 'NO'.

Modifications to the *note 'setup_consumers': performance-schema-setup-consumers-table. table affect monitoring immediately.

If you disable a consumer, the server does not spend time maintaining destinations for that consumer. For example, if you do not care about historical event information, disable the history consumers:

 UPDATE performance_schema.setup_consumers
 SET ENABLED = 'NO'
 WHERE NAME LIKE '%history%';

The consumer settings in the *note 'setup_consumers': performance-schema-setup-consumers-table. table form a hierarchy from higher levels to lower. The following principles apply:

The following lists describe the available consumer values. For discussion of several representative consumer configurations and their effect on instrumentation, see *note performance-schema-consumer-configurations::.

Global and Thread Consumers

Wait Event Consumers

These consumers require both 'global_instrumentation' and 'thread_instrumentation' to be 'YES' or they are not checked. If checked, they act as follows:

Stage Event Consumers

These consumers require both 'global_instrumentation' and 'thread_instrumentation' to be 'YES' or they are not checked. If checked, they act as follows:

Statement Event Consumers

These consumers require both 'global_instrumentation' and 'thread_instrumentation' to be 'YES' or they are not checked. If checked, they act as follows:

Transaction Event Consumers

These consumers require both 'global_instrumentation' and 'thread_instrumentation' to be 'YES' or they are not checked. If checked, they act as follows:

Statement Digest Consumer

The 'statements_digest' consumer requires 'global_instrumentation' to be 'YES' or it is not checked. There is no dependency on the statement event consumers, so you can obtain statistics per digest without having to collect statistics in note 'events_statements_current': performance-schema-events-statements-current-table, which is advantageous in terms of overhead. Conversely, you can get detailed statements in note 'events_statements_current': performance-schema-events-statements-current-table. without digests (the 'DIGEST' and 'DIGEST_TEXT' columns are 'NULL').

For more information about statement digesting, see *note performance-schema-statement-digests::.

 File: manual.info.tmp, Node: performance-schema-consumer-configurations, Next: performance-schema-filtering-names, Prev: performance-schema-consumer-filtering, Up: performance-schema-runtime-configuration

25.4.8 Example Consumer Configurations

The consumer settings in the *note 'setup_consumers': performance-schema-setup-consumers-table. table form a hierarchy from higher levels to lower. The following discussion describes how consumers work, showing specific configurations and their effects as consumer settings are enabled progressively from high to low. The consumer values shown are representative. The general principles described here apply to other consumer values that may be available.

The configuration descriptions occur in order of increasing functionality and overhead. If you do not need the information provided by enabling lower-level settings, disable them and the Performance Schema executes less code on your behalf and you have less information to sift through.

The *note 'setup_consumers': performance-schema-setup-consumers-table. table contains the following hierarchy of values:

 global_instrumentation
  thread_instrumentation
    events_waits_current
      events_waits_history
      events_waits_history_long
    events_stages_current
      events_stages_history
      events_stages_history_long
    events_statements_current
      events_statements_history
      events_statements_history_long
    events_transactions_current
      events_transactions_history
      events_transactions_history_long
  statements_digest

Note:

In the consumer hierarchy, the consumers for waits, stages, statements, and transactions are all at the same level. This differs from the event nesting hierarchy, for which wait events nest within stage events, which nest within statement events, which nest within transaction events.

If a given consumer setting is 'NO', the Performance Schema disables the instrumentation associated with the consumer and ignores all lower-level settings. If a given setting is 'YES', the Performance Schema enables the instrumentation associated with it and checks the settings at the next lowest level. For a description of the rules for each consumer, see *note performance-schema-consumer-filtering::.

For example, if 'global_instrumentation' is enabled, 'thread_instrumentation' is checked. If 'thread_instrumentation' is enabled, the 'events_XXX_current' consumers are checked. If of these 'events_waits_current' is enabled, 'events_waits_history' and 'events_waits_history_long' are checked.

Each of the following configuration descriptions indicates which setup elements the Performance Schema checks and which output tables it maintains (that is, for which tables it collects information).

No Instrumentation

Server configuration state:

 mysql> SELECT * FROM performance_schema.setup_consumers;
 +---------------------------+---------+
 | NAME                      | ENABLED |
 +---------------------------+---------+
 | global_instrumentation    | NO      |
 ...
 +---------------------------+---------+

In this configuration, nothing is instrumented.

Setup elements checked:

Output tables maintained:

Global Instrumentation Only

Server configuration state:

 mysql> SELECT * FROM performance_schema.setup_consumers;
 +---------------------------+---------+
 | NAME                      | ENABLED |
 +---------------------------+---------+
 | global_instrumentation    | YES     |
 | thread_instrumentation    | NO      |
 ...
 +---------------------------+---------+

In this configuration, instrumentation is maintained only for global states. Per-thread instrumentation is disabled.

Additional setup elements checked, relative to the preceding configuration:

Additional output tables maintained, relative to the preceding configuration:

Global and Thread Instrumentation Only

Server configuration state:

 mysql> SELECT * FROM performance_schema.setup_consumers;
 +----------------------------------+---------+
 | NAME                             | ENABLED |
 +----------------------------------+---------+
 | global_instrumentation           | YES     |
 | thread_instrumentation           | YES     |
 | events_waits_current             | NO      |
 ...
 | events_stages_current            | NO      |
 ...
 | events_statements_current        | NO      |
 ...
 | events_transactions_current      | NO      |
 ...
 +----------------------------------+---------+

In this configuration, instrumentation is maintained globally and per thread. No individual events are collected in the current-events or event-history tables.

Additional setup elements checked, relative to the preceding configuration:

Additional output tables maintained, relative to the preceding configuration:

Global, Thread, and Current-Event Instrumentation

Server configuration state:

 mysql> SELECT * FROM performance_schema.setup_consumers;
 +----------------------------------+---------+
 | NAME                             | ENABLED |
 +----------------------------------+---------+
 | global_instrumentation           | YES     |
 | thread_instrumentation           | YES     |
 | events_waits_current             | YES     |
 | events_waits_history             | NO      |
 | events_waits_history_long        | NO      |
 | events_stages_current            | YES     |
 | events_stages_history            | NO      |
 | events_stages_history_long       | NO      |
 | events_statements_current        | YES     |
 | events_statements_history        | NO      |
 | events_statements_history_long   | NO      |
 | events_transactions_current      | YES     |
 | events_transactions_history      | NO      |
 | events_transactions_history_long | NO      |
 ...
 +----------------------------------+---------+

In this configuration, instrumentation is maintained globally and per thread. Individual events are collected in the current-events table, but not in the event-history tables.

Additional setup elements checked, relative to the preceding configuration:

Additional output tables maintained, relative to the preceding configuration:

Global, Thread, Current-Event, and Event-History instrumentation

The preceding configuration collects no event history because the 'events_XXX_history' and 'events_XXX_history_long' consumers are disabled. Those consumers can be enabled separately or together to collect event history per thread, globally, or both.

This configuration collects event history per thread, but not globally:

 mysql> SELECT * FROM performance_schema.setup_consumers;
 +----------------------------------+---------+
 | NAME                             | ENABLED |
 +----------------------------------+---------+
 | global_instrumentation           | YES     |
 | thread_instrumentation           | YES     |
 | events_waits_current             | YES     |
 | events_waits_history             | YES     |
 | events_waits_history_long        | NO      |
 | events_stages_current            | YES     |
 | events_stages_history            | YES     |
 | events_stages_history_long       | NO      |
 | events_statements_current        | YES     |
 | events_statements_history        | YES     |
 | events_statements_history_long   | NO      |
 | events_transactions_current      | YES     |
 | events_transactions_history      | YES     |
 | events_transactions_history_long | NO      |
 ...
 +----------------------------------+---------+

Event-history tables maintained for this configuration:

This configuration collects event history globally, but not per thread:

 mysql> SELECT * FROM performance_schema.setup_consumers;
 +----------------------------------+---------+
 | NAME                             | ENABLED |
 +----------------------------------+---------+
 | global_instrumentation           | YES     |
 | thread_instrumentation           | YES     |
 | events_waits_current             | YES     |
 | events_waits_history             | NO      |
 | events_waits_history_long        | YES     |
 | events_stages_current            | YES     |
 | events_stages_history            | NO      |
 | events_stages_history_long       | YES     |
 | events_statements_current        | YES     |
 | events_statements_history        | NO      |
 | events_statements_history_long   | YES     |
 | events_transactions_current      | YES     |
 | events_transactions_history      | NO      |
 | events_transactions_history_long | YES     |
 ...
 +----------------------------------+---------+

Event-history tables maintained for this configuration:

This configuration collects event history per thread and globally:

 mysql> SELECT * FROM performance_schema.setup_consumers;
 +----------------------------------+---------+
 | NAME                             | ENABLED |
 +----------------------------------+---------+
 | global_instrumentation           | YES     |
 | thread_instrumentation           | YES     |
 | events_waits_current             | YES     |
 | events_waits_history             | YES     |
 | events_waits_history_long        | YES     |
 | events_stages_current            | YES     |
 | events_stages_history            | YES     |
 | events_stages_history_long       | YES     |
 | events_statements_current        | YES     |
 | events_statements_history        | YES     |
 | events_statements_history_long   | YES     |
 | events_transactions_current      | YES     |
 | events_transactions_history      | YES     |
 | events_transactions_history_long | YES     |
 ...
 +----------------------------------+---------+

Event-history tables maintained for this configuration:

 File: manual.info.tmp, Node: performance-schema-filtering-names, Next: performance-schema-instrumentation-checking, Prev: performance-schema-consumer-configurations, Up: performance-schema-runtime-configuration

25.4.9 Naming Instruments or Consumers for Filtering Operations

Names given for filtering operations can be as specific or general as required. To indicate a single instrument or consumer, specify its name in full:

 UPDATE performance_schema.setup_instruments
 SET ENABLED = 'NO'
 WHERE NAME = 'wait/synch/mutex/myisammrg/MYRG_INFO::mutex';

 UPDATE performance_schema.setup_consumers
 SET ENABLED = 'NO'
 WHERE NAME = 'events_waits_current';

To specify a group of instruments or consumers, use a pattern that matches the group members:

 UPDATE performance_schema.setup_instruments
 SET ENABLED = 'NO'
 WHERE NAME LIKE 'wait/synch/mutex/%';

 UPDATE performance_schema.setup_consumers
 SET ENABLED = 'NO'
 WHERE NAME LIKE '%history%';

If you use a pattern, it should be chosen so that it matches all the items of interest and no others. For example, to select all file I/O instruments, it is better to use a pattern that includes the entire instrument name prefix:

 ... WHERE NAME LIKE 'wait/io/file/%';

The pattern ''%/file/%'' matches other instruments that have an element of ''/file/'' anywhere in the name. Even less suitable is the pattern ''%file%'' because it matches instruments with ''file'' anywhere in the name, such as 'wait/synch/mutex/innodb/file_open_mutex'.

To check which instrument or consumer names a pattern matches, perform a simple test:

 SELECT NAME FROM performance_schema.setup_instruments
 WHERE NAME LIKE 'PATTERN';

 SELECT NAME FROM performance_schema.setup_consumers
 WHERE NAME LIKE 'PATTERN';

For information about the types of names that are supported, see *note performance-schema-instrument-naming::.

 File: manual.info.tmp, Node: performance-schema-instrumentation-checking, Prev: performance-schema-filtering-names, Up: performance-schema-runtime-configuration

25.4.10 Determining What Is Instrumented

It is always possible to determine what instruments the Performance Schema includes by checking the *note 'setup_instruments': performance-schema-setup-instruments-table. table. For example, to see what file-related events are instrumented for the 'InnoDB' storage engine, use this query:

 mysql> SELECT * FROM performance_schema.setup_instruments
        WHERE NAME LIKE 'wait/io/file/innodb/%';
 +--------------------------------------+---------+-------+
 | NAME                                 | ENABLED | TIMED |
 +--------------------------------------+---------+-------+
 | 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   |
 +--------------------------------------+---------+-------+

An exhaustive description of precisely what is instrumented is not given in this documentation, for several reasons:

 File: manual.info.tmp, Node: performance-schema-queries, Next: performance-schema-instrument-naming, Prev: performance-schema-runtime-configuration, Up: performance-schema