当前位置:网站首页>Detailed explanation of parallel replication examples in MySQL replication
Detailed explanation of parallel replication examples in MySQL replication
2022-07-01 13:02:00 【1024 questions】
Traditional single thread replication instructions
summary
MySQL5.6 Parallel replication based on Library level
MySQL5.7 Parallel replication based on group commit
Group submission instructions
MySQL8.0 be based on writeset Parallel replication of
View key parameters
Parameter configuration item description
References :
Traditional single thread replication instructionsI/O The thread is responsible for receiving binary logs Event write in Relay Log.SQL Thread reads Relay Log And play it back in the database .as everyone knows ,MySQL stay 5.6 Before the release , There are two threads on the slave node of master-slave replication , Namely I/O Threads and SQL Threads .
1. Main database performs large transactions ( Such as : Large table structure change operation ).2. The main database is changed in large quantities ( Such as : A large number of insert 、 to update 、 Delete operation ).3.ROW In synchronous mode , The primary database large table has no primary key and is frequently updated .4. The database parameter configuration is unreasonable , There is a bottleneck in the slave node performance ( Such as : The setting from the node transaction log is too small , Cause frequent disk brushing ).5. The network environment is unstable , From the node IO Thread reads binlog There is a delay 、 Reconnection .6. The master-slave hardware configuration is different , The hardware resource usage of the slave node has reached the upper limit .( such as : Master node SSD disc , From the node SAS disc )The above methods occasionally cause delay , Then, what are the possible conditions that may cause the delay of the master and slave nodes ?
1. Hardware problems ( Include disk IO、 The Internet IO etc. )2. Configuration problems .3. Database design issues .4. The main database is changed in large quantities , From the node SQL Single thread processing is not timely . summaryThe above reasons for delay can be roughly classified .
MySQL5.6 Parallel replication based on Library levelBy analyzing the above reasons, we can see that to reduce the master-slave delay , In addition to improving the hardware conditions , The other is the need DBA Focus on database design and configuration issues , Finally, it is necessary to improve the concurrent processing capability of the slave node , Changing from single thread playback to multi thread parallel playback is a better method , The key point is how to solve the problem of data conflict and confirmation of fault recovery location point under the premise of multi-threaded recovery .
Thread division executes logicIn the case of multiple databases in the instance , Can open multiple threads , Each thread corresponds to a database . In this mode, the slave node will start multiple threads . Threads fall into two categories
CoordinatorandWorkThread.
Coordinator Threads are responsible for determining whether transactions can be executed in parallel , If it can be done in parallel, the transaction will be distributed to WorkThread Threads execute , If the judgment cannot be executed , Such as DDL, Across the library operation etc. , Just wait for all worker After thread execution , Again by Coordinator perform .
slave-parallel-type=DATABASE The scheme is insufficient MySQL5.7 Parallel replication based on group commit Group submission instructionsThis parallel replication mode , Only in instances where there are multiple DB And DB Only when the transactions of are relatively busy will there be a high degree of parallelism , However, in daily maintenance, the transaction processing of a single instance is relatively concentrated in one DB On . By observing the delay, it can be found that the delay is mainly based on the hotspot table . It is a good way to provide table based parallelism .
Simply put, it is in the double 1 Set up , After the transaction is committed, the disk flushing operation is changed to merge multiple transactions into a group of transactions, and then perform Unified Disk flushing , This process lowers the disk IO The pressure of the . Details reference
Lao Ye teahouseTweets about group submissionshttps://mp.weixin.qq.com/s/rcPkrutiLc93aTblEZ7sFg
A group of transactions are committed at the same time, which means that there is no conflict between transactions in the group , Therefore, the transactions in the group can be executed concurrently on the slave node , The problem is how to distinguish whether transactions are in the same group , So in binlog Two new parameter messages appear in last_committed and sequence_number
analysis binlog You can see there's more in it
last_committedandsequence_numberTwo parameter information , amonglast_committedThere is duplication .
sequence_number # This value refers to the sequence number of the transaction commit , Monotone increasing . last_committed # This value has two meanings ,1. The same value means that these transactions are in the same group ,2. This value is also the maximum number representing the last set of transactions . [[email protected] GreatSQL]# mysqlbinlog mysql-bin.0000002 | grep last_committedGTID last_committed=0 sequence_number=1GTID last_committed=0 sequence_number=2GTID last_committed=2 sequence_number=3GTID last_committed=2 sequence_number=4GTID last_committed=2 sequence_number=5GTID last_committed=2 sequence_number=6GTID last_committed=6 sequence_number=7GTID last_committed=6 sequence_number=8 Database configuration slave-parallel-type=LOGICAL_CLOCK The scheme is insufficient binlog_group_commit_sync_delay # Time to wait for late submission ,binlog Wait for a while after submitting fsync. Let each group More things to do , Artificially improve the parallelism .binlog_group_commit_sync_no_delay_count # Maximum number of transactions to be committed , If the waiting time is not up , The number of transactions reached , Right now fsync. Commit as soon as the desired parallelism is reached , Try to minimize the waiting delay . MySQL8.0 be based on writeset Parallel replication ofThere is a deficiency in group based synchronization , That is, when the transaction busy degree of the primary node is low , Results in group submission in the time period fsync The amount of disk flushing transactions is less , As a result, the parallelism of playback from the library is not high , There may even be only one transaction in a group , In this way, the multithreading of slave nodes is basically unnecessary , You can set the following two parameters , Let the master node delay the submission .
View key parameterswriteset A method to judge whether a transaction can be played back in parallel based on the conflict of transaction results , He is made up of
binlog-transaction-dependency-trackingParameter control , By defaultWRITESETMethod .
| System Variable | binlog_transaction_dependency_tracking |
| Scope | Global |
| Dynamic | Yes |
| SET_VAR Hint Applies | No |
| Type | Enumeration |
| Default Value | COMMIT_ORDER |
| Valid Values | COMMIT_ORDER WRITESET WRITESET_SESSION |
COMMIT_ORDER # Use 5.7 Group commit The way in which the transaction depends . WRITESET # Determine transaction dependencies by writing collections . WRITESET_SESSION # Use write set , But the same session Transactions in cannot have the same last_committed. writeset It's a HASH An array of types , It records the updated information of the transaction , adopt
transaction_write_set_extractionJudge whether the record updated by the current transaction conflicts with the record updated by the historical transaction , After judgment, the corresponding treatment method shall be adopted .writeset The maximum stored value is determined bybinlog-transaction-dependency-history-sizecontrol .
binlog_transaction_dependency_history_sizeIt should be noted that , When set to
WRITESETorWRITESET_SESSIONWhen , Transaction commit is out of order , Can be set byslave_preserve_commit_order=1Force sequential submission .
Set the maximum number of row hashes saved in memory , Used to cache row information modified by previous transactions . Once this hash number is reached , Will clear the history .
| System Variable | binlog_transaction_dependency_history_size |
| Scope | Global |
| Dynamic | Yes |
| SET_VAR Hint Applies | No |
| Type | Integer |
| Default Value | 25000 |
| Minimum Value | 1 |
| Minimum Value | 1000000 |
This mode supports three algorithms , By default XXHASH64, When the slave node is configured writeset When copying , This configuration cannot be configured as OFF. This parameter is already in MySQL 8.0.26 Abandoned in , It will be deleted later .
| Deprecated | 8.0.26 |
| System Variable | binlog_transaction_dependency_history_size |
| Scope | Global, Session |
| Dynamic | Yes |
| SET_VAR Hint Applies | No |
| Type | Enumeration |
| Default Value | XXHASH64 |
| Valid Values | OFF MURMUR32 XXHASH64 |
Database configuration
slave_parallel_type = LOGICAL_CLOCKslave_parallel_workers = 8binlog_transaction_dependency_tracking = WRITESETslave_preserve_commit_order = 1 References : Ali kernel monthly : http://mysql.taobao.org/monthly/2018/06/04/ Official documents : https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.htmlThis is about MySQL Replication This is the end of the article on parallel replication , More about MySQL Please search the previous articles of SDN or continue to browse the relevant articles below. I hope you will support SDN more in the future !
边栏推荐
- Ustime wrote a bug
- Topic 2612: the real topic of the 12th provincial competition of the Blue Bridge Cup in 2021 - the least weight (enumerating and finding rules + recursion)
- 彩色五角星SVG动态网页背景js特效
- 有没有大佬 遇到过flink监控postgresql数据库, 检查点无法使用的问题
- 木架的场景功能
- 数论基础及其代码实现
- 科学创业三问:关于时机、痛点与重要决策
- 腾讯总考epoll, 很烦
- Different test techniques
- 用.Net Core接入微信公众号开发
猜你喜欢

shell脚本导入存储过程到数据库

【大型电商项目开发】性能压测-压力测试基本概念&JMeter-38

Introduction to reverse debugging PE structure input table output table 05/07

Fiori applications are shared through the enhancement of adaptation project

MySQL statistical bill information (Part 2): data import and query

Vs code set code auto save

基于开源流批一体数据同步引擎 ChunJun 数据还原 —DDL 解析模块的实战分享

Operator-1初识Operator

Ikvm of toolbox Net project new progress

Function test process in software testing
随机推荐
数字化转型再下一城,数字孪生厂商优锘科技宣布完成超3亿元融资
ZABBIX 6.0 source code installation and ha configuration
MHA high availability cluster deployment and failover of database
Report on the "14th five year plan" and investment strategy recommendations for China's industrial robot industry 2022 ~ 2028
Router.use() requires a middleware function but got a Object
Interpretation of hard threshold function [easy to understand]
c语言学习
Which securities company has a low, safe and reliable account opening commission
基因检测,如何帮助患者对抗疾病?
MySQL gap lock
Function test process in software testing
Hardware development notes (9): basic process of hardware development, making a USB to RS232 module (8): create asm1117-3.3v package library and associate principle graphic devices
Redis exploration: cache breakdown, cache avalanche, cache penetration
逆向调试入门-PE结构-输入表输出表05/07
leetcode:226. Flip binary tree [DFS flip]
Topic 2612: the real topic of the 12th provincial competition of the Blue Bridge Cup in 2021 - the least weight (enumerating and finding rules + recursion)
基于mysql乐观锁实现秒杀的示例代码
网络socket的状态要怎么统计?
【牛客刷题-SQL大厂面试真题】NO2.用户增长场景(某度信息流)
codeforces -- 4B. Before an Exam