MySQL 5.7 并行复制参数优化

时间:2024-04-07 19:33:34

MySQL 5.7 并行复制参数优化

mysql 并行同步原理图如上。

Enhanced Multi-Threaded Slave配置
要开启enhanced multi-threaded slave其实很简单,只需根据如下设置:

slave

slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=16
master_info_repository=TABLE
relay_log_info_repository=TABLE
relay_log_recovery=ON

并行复制监控

在配置完成后,performance_schema mysql 的性能视图表,增加了以下表,
方便进行主从同步的性能监控。

[email protected]: (performance_schema)>show tables like ‘replication%’;
+———————————————+
| Tables_in_performance_schema (replication%) |
+———————————————+
| replication_applier_configuration |
| replication_applier_status |
| replication_applier_status_by_coordinator |
| replication_applier_status_by_worker |
| replication_connection_configuration |
| replication_connection_status |
| replication_group_member_stats |
| replication_group_members |
+———————————————+
8 rows in set (0.01 sec)

参数优化说明:

slave

slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=4

master_info_repository=TABLE
relay_log_info_repository=TABLE
relay_log_recovery=ON

slave_parallel_workers
若将slave_parallel_workers设置为0,则MySQL 5.7退化为原单线程复制,
但将slave_parallel_workers设置为1,则SQL线程功能转化为coordinator线程,
但是只有1个worker线程进行回放,也是单线程复制。然而,这两种性能却又有一些的区别,因为多了一次coordinator线程的转发,
因此slave_parallel_workers=1的性能反而比0还要差,经测试还有20%左右的性能下降,

master_info_repository ,relay_log_info_repository
两个参数的值有2种设置类型: file,table,

将参数master_info_repostitory设置为TABLE,这样性能可以有50%~80%的提升。

当设置为table 后,之前的文件:
master.info
relay-log.info 将被删除消失。
代之的是两个表,可以在表中进行查询相关信息。。
mysql.slave_master_info
mysql.slave_relay_log_info

[email protected]: (test)>select * from mysql.slave_master_info\G
***************** 1. row *****************
Number_of_lines: 25
Master_log_name: mysql-bin.000022
Master_log_pos: 3901814
Host: 10.20.0.11
User_name: repl
User_password: 123456
Port: 3001
Connect_retry: 60
Enabled_ssl: 0
Ssl_ca:
Ssl_capath:
Ssl_cert:
Ssl_cipher:
Ssl_key:
Ssl_verify_server_cert: 0
Heartbeat: 30
Bind:
Ignored_server_ids: 0
Uuid: 403d88ce-f9d6-11e7-a86f-0050563dd912
Retry_count: 86400
Ssl_crl:
Ssl_crlpath:
Enabled_auto_position: 0
Channel_name:
Tls_version:
1 row in set (0.01 sec)

[email protected]: (test)>select * from mysql.slave_relay_log_info\G
***************** 1. row *****************
Number_of_lines: 7
Relay_log_name: /opt/data/mysql/mysql-relay-bin.000002
Relay_log_pos: 3902791
Master_log_name: mysql-bin.000022
Master_log_pos: 3902625
Sql_delay: 0
Number_of_workers: 4
Id: 1
Channel_name:
1 row in set (0.15 sec)

2表字段说明请看URL: https://blog.csdn.net/xxj123go/article/details/72828883