author : Peng Bo Li
Love can be born DBA Team members , Will change , Mainly responsible for MySQL Troubleshooting and SQL Audit optimization . A commitment to technology , Be responsible for the customer .
In this paper, the source : Original contribution
* Produced by aikesheng open source community , Original content is not allowed to be used without authorization , For reprint, please contact the editor and indicate the source .
With MySQL The version is constantly updated , Yes DDL The operation support is also constantly improved and updated : For instance from MySQL 5.6 introduce Online DDL , stay MySQL 5.7 Yes Online DDL Further refinement , To the present 8.0 edition , On the other hand DDL The implementation of is redesigned , such as DDL The operation supports atomic properties , stay MySQL 8.0.27 Introduce parallelism DDL . This article will explore MySQL 8.0.27 Parallel of DDL about DDL Increase of operating speed .
MySQL 8.0.14 Introduced innodb_parallel_read_threads Variable to control the parallel thread scanning the cluster index .MySQL 8.0.27 Introduced innodb_ddl_threads Variable to control the number of parallel threads used to create secondary indexes , This parameter is generally introduced together with innodb_ddl_buffer_size Use it together ,innodb_ddl_buffer_size Used to specify parallel processing DDL Can be used during operation buffer size ,buffer In all DDL The average number of threads allocated in parallel , So generally, if you turn it up innodb_ddl_threads variable , It also needs to be turned up innodb_ddl_buffer_size Size .
innodb_ddl_threads 、innodb_ddl_buffer_size and innodb_parallel_read_threads The default sizes of are :
mysql> select @@global.innodb_ddl_threads;
+-----------------------------+
| @@global.innodb_ddl_threads |
+-----------------------------+
| 4 |
+-----------------------------+
1 row in set (0.00 sec)
mysql> select @@global.innodb_ddl_buffer_size;
+---------------------------------+
| @@global.innodb_ddl_buffer_size |
+---------------------------------+
| 1048576 |
+---------------------------------+
1 row in set (0.00 sec)
mysql> select @@global.innodb_parallel_read_threads;
+---------------------------------------+
| @@global.innodb_parallel_read_threads |
+---------------------------------------+
| 4 |
+---------------------------------------+
1 row in set (0.00 sec)
Next, test a big innodb_ddl_threads 、innodb_ddl_buffer_size and innodb_parallel_read_threads The parameter value pairs DDL Performance improvement of operation .
First create a 5000 Ten thousand watches :
-- The database version is 8.0.28
mysql> select @@version;
+----------+
| @@version|
+----------+
| 8.0.28 |
+----------+
1 row in set (0.00 sec)
-- buffer pool The size is 24G
mysql> select @@global.innodb_buffer_pool_size;
+----------------------------------+
| @@global.innodb_buffer_pool_size |
+----------------------------------+
| 25769803776 |
+----------------------------------+
1 row in set (0.001 sec)
mysql> create database action;
Query OK, 1 row affected (0.01 sec)
# sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-socket=/data/mysql/data/3306/mysqld.sock --mysql-user=root --mysql-password='123' --mysql-db=action --tables=1 --table-size=50000000 --report-interval=1 --threads=8 prepare
mysql> select count(*) from action.sbtest1;
+----------+
| count(*) |
+----------+
| 50000000 |
+----------+
1 row in set (21.64 sec)
-- The table space size is 12G
# ll -h
total 12G
-rw-r-----. 1 mysql mysql 12G Jan 20 17:38 sbtest1.ibd
Test the performance of different number of threads and buffer size DDL Operating time , for example :
-- Set up concurrency DDL Thread is 1
mysql> set innodb_ddl_threads = 1;
Query OK, 0 rows affected (0.01 sec)
-- Set up buffer The size is 512M
mysql> set innodb_ddl_buffer_size = 536870912;
Query OK, 0 rows affected (0.00 sec)
-- Set the parallel index scanning thread to 1
mysql> set innodb_parallel_read_threads = 1;
Query OK, 0 rows affected (0.01 sec)
-- perform DDL operation
mysql> alter table action.sbtest1 add index idx_c(c);
Query OK, 0 rows affected (6 min 54.21 sec)
Records: 0 Duplicates: 0 Warnings: 0
-- see DDL The maximum memory usage of
mysql> select event_name,CURRENT_NUMBER_OF_BYTES_USED/1024/1024 from performance_schema.memory_summary_global_by_event_name where event_name='memory/innodb/ddl';
+-------------------+----------------------------------------+
| event_name | CURRENT_NUMBER_OF_BYTES_USED/1024/1024 |
+-------------------+----------------------------------------+
| memory/innodb/ddl | 513.08750916 |
+-------------------+----------------------------------------+
1 row in set (0.00 sec)
By continuously adjusting relevant parameters, the following results are obtained :
innodb_ddl_threads | innodb_ddl_buffer_size | innodb_parallel_read_threads | DDL Maximum memory consumption | DDL Time |
---|---|---|---|---|
1 | 512M | 1 | 513M | 6 min 54.21 sec |
2 | 1G | 2 | 1230M | 4 min 12.08 sec |
4 | 2G | 4 | 2735M | 3 min 43.01 sec |
8 | 4G | 8 | 5791M | 3 min 19.63 sec |
16 | 8G | 16 | 5975M | 3 min 12.33 sec |
32 | 16G | 32 | 6084M | 3 min 11.11 sec |
You can see , With the increase of concurrent threads and buffer An increase in ,DDL The more resources the operation takes up , and DDL The less time it takes to operate . But by comparing the consumption of resources with DDL The rate of increase in speed , The most reasonable number of parallel threads is 4-8 individual , and buffer The size can be adjusted according to the situation .
Reference link :https://dev.mysql.com/doc/ref...