[MySQL 5.6] 优化函数lock_number_of_rows_locked

lock_number_of_rows_locked是一个统计一个事务中占有多少记录锁的函数,通过执行show engine innodb status触发。

在我们的生产环境中,类似SHOW ENGINE INNODB STATUS这样的语句是被频繁执行的,而从perf top,也观察到过占用超过20%的cpu。

quoted code from lock_number_of_rows_locked:

       for (lock = UT_LIST_GET_FIRST(trx_lock->trx_locks);
            lock != NULL;
            lock = UT_LIST_GET_NEXT(trx_locks, lock)) {

               if (lock_get_type_low(lock) == LOCK_REC) {
                       ulint   n_bit;
                       ulint   n_bits = lock_rec_get_n_bits(lock);

                       for (n_bit = 0; n_bit < n_bits; n_bit++) {
                               if (lock_rec_get_nth_bit(lock, n_bit)) {
                                       n_records++;
                               }
                       }
               }
       }

 

返回上一层的函数来看,这里实际上是带着全局大锁lock_sys->mutex.仅仅为了一个计数,我们完全可以为每个事务增加一个计数器,然后在设置行锁bit/RESET 行锁bit时 增加/减少计数.

昨天提交的buglist(http://bugs.mysql.com/bug.php?id=68647) ,包含Patch

 

原创文章,转载请注明: 转载自Simple Life

本文链接地址: [MySQL 5.6] 优化函数lock_number_of_rows_locked

Post Footer automatically generated by wp-posturl plugin for wordpress.


Comments

Leave a Reply

Your email address will not be published. Name and email are required


Current month ye@r day *