SELECT COUNT_STAR, SUM_TIMER_WAIT, AVG_TIMER_WAIT, EVENT_NAME
FROM performance_schema.events_waits_summary_global_by_event_name
where COUNT_STAR >
0 and EVENT_NAME
like 'wait/synch/%' order by SUM_TIMER_WAIT
desc limit 10; +
------------+------------------+----------------+--------------------------------------------+ | COUNT_STAR | SUM_TIMER_WAIT | AVG_TIMER_WAIT | EVENT_NAME |
+
------------+------------------+----------------+--------------------------------------------+ | 36847781 | 1052968694795446 | 28575867 | wait/synch/mutex/innodb/lock_mutex |
| 8096 | 81663413514785 | 10086883818 | wait/synch/cond/threadpool/timer_cond |
| 19 | 3219754571347 | 169460766775 | wait/synch/cond/threadpool/worker_cond |
| 12318491 | 1928008466219 | 156446 | wait/synch/mutex/innodb/trx_sys_mutex |
| 36481800 | 1294486175099 | 35397 | wait/synch/mutex/innodb/trx_mutex |
| 14792965 | 459532479943 | 31027 | wait/synch/mutex/innodb/os_mutex |
| 2457971 | 62564589052 | 25346 | wait/synch/mutex/innodb/mutex_list_mutex |
| 2457939 | 62188866940 | 24909 | wait/synch/mutex/innodb/rw_lock_list_mutex |
| 201370 | 32882813144 | 163001 | wait/synch/rwlock/innodb/hash_table_locks |
| 1555 | 15321632528 | 9853039 | wait/synch/mutex/innodb/dict_sys_mutex |
+
------------+------------------+----------------+--------------------------------------------+ 10 rows in
set (0.01 sec)
從上面的表可以確認,lock_mutex(在MySQL源碼里對應的是lock_sys->mutex)的鎖等待累積時間最長(SUM_TIMER_WAIT)。lock_sys表示全局的InnoDB鎖系統,在源碼里看到InnoDB加/解某個記錄鎖的時候(這個case里是X鎖),同時需要維護lock_sys,這時會請求lock_sys->mutex。
在這個case里,因為在Searching rows for update的階段頻繁地加/解X鎖,就會頻繁請求lock_sys->mutex,導致lock_sys->mutex鎖總等待時間過長,同時在等待的時候消耗了大量CPU。