Ch 02: Monitoring Locks and Mutexes

The Performance Schema contains the source of most of the locks information available except for deadlocks.

metadata_locks table

To record information, the wait/lock/metadata/sql/model Performance Schema instrument must be enabled (it is enabled by default in MySQL 8.0).

Data locks are at the medium level between the metadata locks and the synchronization object.

Synchronization Waits

Categories:

  1. cond
  2. mutex
  3. prlock (priority read lock)
  4. rwlock (read/write lock)
  5. sxlock (INNODB only for B-Tree searches)

wait/synch/mutex/innodb/dbwr_mutex

Can use UPDATE. Better to use configuration file.

Enabling monitoring on a production systems could cause an outage.

event_waits_% views - needs associated consumers to be enabled.

Given how short lived a synchronization wait normally is and how frequently they are encountered, the summary tables are usually the most useful for investigating waits using the Performance Schema.

Statement and Error Tables

SET SESSION innodb_lock_wait_timeout = <n>;
ERROR 1205: Lock wait timeout exceeded; try restarting transaction
SHOW TABLES FROM performance_schema LIKE '%error%';

The events_errors_summary_global_by_error is populated with all known errors from the time MySQL is started even if the error has not yet been encountered. So, you can safely query for specific errors at all times including using the table to look up the error number from the name.

SYS Schema

X$ unformatted data

Status Counters and INNODB Metrics

The global status counters can be found in the performance_schema.global_status table or with the SHOW GLOBAL STATS statement. The INNODB metrics are found in the performance_schema.INNODB_METRICS view.

INNODB mutexes/semaphores contention (innodb_rwlock_% metrics)

Configuring the INNODB Metrics

Caution: The metrics have varying overheads, so you are recommended to test with your workload before enabling in production.

By enabling the innodb_status_output_locks option (disabled by default), all locks will be listed; this is similar to what you have in the Performance Schema data_locks table.

You generate the InnodB lock monitor output using the SHOW INNODB STATUS statement.

Nowadays, the lock information in the INNODB monitor output is better obtained from the performance_schema.data_locks and performance_schema.data_lock_waits tables. The deadlock information is however still very useful.

innodb_status_option dump info every 15 secs

innodb_print_all_deadlocks

InnoDB Mutexes and Semaphores

In InnoDB monitoring, there is no clear distinction between mutexes and semaphores.

SHOW ENGINE INNODB MUTEX only includes mutexes and rw-lock semaphores that has had at least one OS wait.

There is usally no reason to disable the latch metric.