当前位置:网站首页>Speed adjustment of tidb DDL

Speed adjustment of tidb DDL

2022-06-11 17:33:00 On the way to data communication

One 、 Description of the environment

ip Components To configure
192.168.1.1tidb、pd、tikv2c4g
192.168.1.2tidb、pd、tikv2c4g
192.168.1.3tidb、pd、tikv2c4g

Two 、 Experimental environment preparation

1. Build table

# ddl_1,ddl_2,ddl_3 The table structure is consistent 
CREATE TABLE `ddl_1` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `z_name` varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `z_info` varchar(30) COLLATE utf8mb4_general_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci

2. Insert

import pymysql
conn = pymysql.Connect()
cur = conn.cursor()
# ddl_1,ddl_2,ddl_3 insert data 
sql_str = 'insert into ddl_2(z_name, z_info) values("csdfsdfsdfsda", "qwwerwerisdfnsdvj vsd")'
for i in range(1000):
    sql_str = sql_str + ',("csdfsdfsdfsda", "qwwerwerisdfnsdvj vsd")'
for i in range(1000):
    print(i)
    cur.execute(sql_str)
    conn.commit()
conn.close()

3. View table information

mysql> show table ddl_2 regions\G
*************************** 1. row ***************************
           REGION_ID: 1149
           START_KEY: t_80_
             END_KEY: t_85_
           LEADER_ID: 1152
     LEADER_STORE_ID: 5
               PEERS: 1150, 1151, 1152
          SCATTERING: 0
       WRITTEN_BYTES: 0
          READ_BYTES: 0
APPROXIMATE_SIZE(MB): 108
    APPROXIMATE_KEYS: 1346062
1 row in set (0.02 sec)

mysql> show table ddl_1 regions\G
*************************** 1. row ***************************
           REGION_ID: 2
           START_KEY: t_85_
             END_KEY:
           LEADER_ID: 3
     LEADER_STORE_ID: 1
               PEERS: 3, 6, 7
          SCATTERING: 0
       WRITTEN_BYTES: 0
          READ_BYTES: 0
APPROXIMATE_SIZE(MB): 97
    APPROXIMATE_KEYS: 1013491
1 row in set (0.10 sec)

mysql> show table ddl_3 regions\G
*************************** 1. row ***************************
           REGION_ID: 2
           START_KEY: t_89_
             END_KEY:
           LEADER_ID: 3
     LEADER_STORE_ID: 1
               PEERS: 3, 6, 7
          SCATTERING: 0
       WRITTEN_BYTES: 0
          READ_BYTES: 93093000
APPROXIMATE_SIZE(MB): 101
    APPROXIMATE_KEYS: 1031510
1 row in set (0.01 sec)

4. Add index

mysql> alter table ddl_1 add index idx_z_info(z_info);
Query OK, 0 rows affected (2 min 16.17 sec)

set global tidb_ddl_reorg_batch_size=1024;
mysql> alter table ddl_2 add index idx_z_info(z_info);
Query OK, 0 rows affected (1 min 44.53 sec)

set global tidb_ddl_reorg_worker_cnt=8;
mysql> alter table ddl_3 add index idx_z_info(z_info);
Query OK, 0 rows affected (1 min 40.01 sec)

5. control ddl Related parameters of

Parameters significance
ddl_slow_threshold Time consuming beyond this threshold DDL The operation will be output to the log
tidb_ddl_error_count_limit Used to control DDL Number of retries for operation failure . After the number of failed retries exceeds the value of this parameter , Will cancel the error DDL operation
tidb_ddl_reorg_priority Used to set ADD INDEX operation re-organize Execution priority of the phase , Can be set to PRIORITY_LOW/PRIORITY_NORMAL/PRIORITY_HIGH
tidb_ddl_reorg_batch_size Used to set DDL operation re-organize Stage batch size, such as ADD INDEX operation , Need to backfill index data , By concurrency tidb_ddl_reorg_worker_cnt individual worker Backfill data together , Every worker With batch Backfill per unit
tidb_ddl_reorg_worker_cnt Used to set DDL operation re-organize Concurrency of phases

3、 ... and 、 Comparison conclusion

tidb_ddl_reorg_batch_sizetidb_ddl_reorg_worker_cnt execution time Consume cpu
2564136s102%
10244104s128%
10248100s130%

Conclusion : From the test results , The bigger tidb_ddl_reorg_batch_size, The bigger tidb_ddl_reorg_worker_cnt Faster execution time , At the same time, it will bring higher cpu

原网站

版权声明
本文为[On the way to data communication]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111719373813.html