|
MutexContentionStats
Statistics for mutexes
NoteThis code has been built on an x86-64 server that uses gcc and Linux 2.6. I don't know if it works on other platforms. The code is here for 5.1.26 and here for 5.1.31. IntroductionThis patch provides mutex contention statistics for MySQL via the SQL command SHOW GLOBAL MUTEX STATUS. It is similar to the output provided for InnoDB mutexes by the SQL command SHOW MUTEX STATUS. It optionally reports lock waits by caller. To enable it, apply this patch, run configure with the --with-fast-mutexes option and build. To get lock waits by caller, run configure with -with-fast-mutexes C_EXTRA_FLAGS=-DMY_COUNT_MUTEX_CALLERS. The fast mutex code uses busy-wait loops before blocking on lock requests. If the lock is not obtained during the busy-wait loop, the code assumes that the caller has to block on the lock request. The duration of the busy-wait loop is determined by the my.cnf variable mysql_spin_wait_loops. The default value is 100 which produces a ~6 microsecond delay on a current x86_64 CPU. The delay is measured at mysqld startup and printed in the database error log. It is also displayed in the SHOW STATUS variable Mysql_spin_wait_microseconds. This patch also changes all pthread_mutex_init calls to use MY_MUTEX_INIT_FAST. I won't claim that fast mutexes improve performance. But they make it possible to estimate mutex contention. I use this for performance testing builds. The data is exported by the SQL command SHOW GLOBAL MUTEX STATUS. Sample output is displayed below. The output has several columns:
Sample output: Locks Spins Sleeps Name Line Users 1 0 0 my_thr_init.c 287 68 172 0 0 mysqld.cc 3081 1 0 0 0 slave.h 453 1 4229999 114473 1883 thr_lock.c 319 111742 0 0 -225 thr_lock.c 325 0 This displays the estimated busy-wait time. show status like "%spin%"; Variable_name Value Mysql_spin_wait_microseconds 6 The statistics may be inaccurate:
ThanksI copied code from InnoDB for hashing and random number generation. Thanks InnoDB. |
Sign in to add a comment
Great Mark,
I guess you do not have an option of timing "sleeps" right ?
Mark,
do you need patch of sql_yacc.cc in the patch ?
@peter - there is no option for timing. I know that others want it for some cases.
@apachephp - sql_yacc.cc should be regenerated after sql_yacc.yy is generated. It is not included to reduce the size of the patch.