innodb的锁、update单条记录的花费时间压测

观察innodb的锁时间,需要关注:

mysqladmin extended-status -r -i 1 -uroot | grep "Innodb_row_lock_time"

或show status like '%lock%';

      Innodb_row_lock_current_waits:当前正在等待锁定的数量;

      Innodb_row_lock_time :从系统启动到现在锁定的总时间长度,单位ms;

      Innodb_row_lock_time_avg :每次等待所花平均时间;

      Innodb_row_lock_time_max:从系统启动到现在等待最长的一次所花的时间;

      Innodb_row_lock_waits :从系统启动到现在总共等待的次数。

如我的压测语句:

insert into i0( id, type, num, iid, uid, iid, sid,bid, cid, q, gmt_create, gmt_modified, status, version, time_out, time_number, o_gmt_create,aid, ff, flag, code, cache, sq, rq) values( :v_id, '1',:v_opt_num, '1352', 1640350003, 16441266176, 0, '1370761289618','19101339145067259', '2', now(), now(), '1', '0', null, '0', now(), '0', null, '2', 'C', 1, null, null);
  update q0 set q=q-0, v=v+1, gmt_modified=now(), rq = CASE WHEN ((rq + 2 ) >= 0 ) then rq + 2 ELSE 0 END where id =6060 and iid = 16441266176 and sid = 0 and (q - rq - 2) >= 0 and q-0>=0;

压测结果:

Summary: SQL01 exec=11756, rows=11756=100/e, avg=518 us
Summary: SQL02 exec=12800, rows=12800=100/e, avg=14483 us
Summary: exec=8488/s, qtps=16343/s

观察到的锁情况:

复制代码
| Innodb_row_lock_time                     | 868           |
| Innodb_row_lock_time_avg                 | 0             |
| Innodb_row_lock_time_max                 | 0             |
| Innodb_row_lock_time                     | 114932        |
| Innodb_row_lock_time_avg                 | 0             |
| Innodb_row_lock_time_max                 | 0             |
| Innodb_row_lock_time                     | 61775         |
| Innodb_row_lock_time_avg                 | 0             |
| Innodb_row_lock_time_max                 | 0             |
| Innodb_row_lock_time                     | 0             |
复制代码

从占有锁到释放锁一共消耗:114932ms,不可能是一条记录的时间,再根据实时状态:

复制代码
-------- -----load-avg---- ---cpu-usage--- ---swap---                     -QPS- -TPS-         -Hit%- ---innodb rows status--- 
  time  |  1m    5m   15m |usr sys idl iow|   si   so|  ins   upd   del    sel   iud|     lor    hit|  ins   upd   del   read|
19:47:20| 1.26  1.21  1.20|  5   1  93   0|    0    0|    0     0     0      0     0|       0 100.00|    0     0     0      0|
19:47:21| 1.26  1.21  1.20|  1   1  98   0|    0    0|    0     1     0      5     1|       9 100.00|    0     1     0      1|
19:47:22| 1.24  1.21  1.20|  0   0 100   0|    0    0|    0     0     0      6     0|       1 100.00|    0     0     0      0|
19:47:23| 1.24  1.21  1.20|  7   3  90   0|    0    0| 2932  2930     0      6  5862|  100502  99.91| 2712  2809     0   2809|
19:47:24| 1.24  1.21  1.20| 16   4  79   0|    0    0| 7939  7940     0      6 15879|  293693  99.91| 7257  7954     0   7954|
19:47:25| 1.24  1.21  1.20|  5   2  93   0|    0    0| 1929  1932     0      6  3861|  101527  99.94| 1762  2039     0   2039|
复制代码

实际每秒update 7940条,平均每条消耗:

root@(none) 07:47:33>select 114932/7940ms;
+-------------+
| 114932/7940 |
+-------------+
|     14.4751 |
+-------------+

平均每条消耗14.4751ms和压测结果avg=14483 us吻合,对于单条语句的更新来说这个锁占用的时间还是挺长的。

 

死锁:

show engine innodb status;

查出的

------------------------
LATEST DETECTED DEADLOCK
------------------------
posted on 2016-12-09 11:14  duanxz  阅读(650)  评论(0编辑  收藏  举报