Online DDL锁表时间优化

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sun_ashe/article/details/81433903

online DDL指的是DDL执行期间的绝大部门内部处理工作不阻塞DML操作,但是在某些阶段还是会影响。
对于可以采取online操作的ddl操作,其锁表累计时间主要由DDL期间的DML操作数量,以及参数值innodb_sort_buffer_size。

先看波儿测试

测试如下:
innodb_sort_buffer_size | 67108864
[ 51s] threads: 200, tps: 2793.87, reads: 39217.23, writes: 10513.52, response time: 29.95ms (95%), errors: 1.00, reconnects: 0.00
[ 52s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 53s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 54s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 55s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 56s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 57s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 58s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 59s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 60s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 61s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 62s] threads: 200, tps: 5604.11, reads: 78361.59, writes: 22779.46, response time: 38.27ms (95%), errors: 8.00, reconnects: 0.00

innodb_sort_buffer_size | 8388608
[ 78s] threads: 200, tps: 11748.18, reads: 165047.55, writes: 46637.72, response time: 26.38ms (95%), errors: 10.00, reconnects: 0.00
[ 79s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 80s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 81s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 82s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 83s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 84s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 85s] threads: 200, tps: 10036.42, reads: 140068.86, writes: 40416.69, response time: 29.31ms (95%), errors: 5.00, reconnects: 0.00

innodb_sort_buffer_size | 4194304
[ 11s] threads: 200, tps: 7718.00, reads: 108368.99, writes: 30927.00, response time: 32.30ms (95%), errors: 7.00, reconnects: 0.00
[ 12s] threads: 200, tps: 7581.72, reads: 106756.04, writes: 29984.89, response time: 29.05ms (95%), errors: 11.00, reconnects: 0.00
[ 13s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 14s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 15s] threads: 200, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 0.00, reconnects: 0.00
[ 16s] threads: 200, tps: 568.05, reads: 7477.63, writes: 2617.22, response time: 4337.67ms (95%), errors: 3.00, reconnects: 0.00
[ 17s] threads: 200, tps: 12316.98, reads: 172692.75, writes: 49210.93, response time: 27.57ms (95%), errors: 8.00, reconnects: 0.00

但是不能再小了,如果设置太小,可能会遇到如下错误,正在排查中。目前不清楚具体原因
mysql> alter table sbtest1 add index(k);
ERROR 1034 (HY000): Incorrect key file for table ‘sbtest1’; try to repair it

再看波儿原理解释

需要先了解下row log,online ddl的几个阶段,以及客户端dml操作在ddl期间的额外操作。

row log

image_1cd2fom4ar0g4dd10hqhbocn9.png-45.3kB

对于row log的锁竞争

对于innodb表来讲,索引就是数据,数据就是索引。那数据的插入,更新,删除操作,其实就是对应的索引页上的操作,

猜你喜欢

转载自blog.csdn.net/sun_ashe/article/details/81433903