当前位置:网站首页>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 !
边栏推荐
- 软件测试中功能测试流程
- 买卖其实也有风险
- What are the solutions for session sharing of highly paid programmers & interview questions series 118?
- 简单的两个圆球loading加载
- Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
- redis探索之缓存一致性
- 图灵奖得主Judea Pearl:最近值得一读的19篇因果推断论文
- The popular major I chose became "Tiankeng" four years later
- 硬件开发笔记(九): 硬件开发基本流程,制作一个USB转RS232的模块(八):创建asm1117-3.3V封装库并关联原理图元器件
- leetcode:241. 为运算表达式设计优先级【dfs + eval】
猜你喜欢

redis探索之缓存一致性

Operator-1 first acquaintance with operator

codeforces -- 4B. Before an Exam

Wang Xing's infinite game ushers in the "ultimate" battle

Vs code setting Click to open a new file window without overwriting the previous window

晓看天色暮看云,美图欣赏

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

【牛客刷题-SQL大厂面试真题】NO2.用户增长场景(某度信息流)

VM虚拟机配置动态ip和静态ip访问

Svg diamond style code
随机推荐
有人碰到过这种情况吗,oracle logminer 同步的时候,clob字段的值丢失
基于开源流批一体数据同步引擎 ChunJun 数据还原 —DDL 解析模块的实战分享
Redis exploration: cache breakdown, cache avalanche, cache penetration
Scene function of wooden frame
【大型电商项目开发】性能压测-压力测试基本概念&JMeter-38
[encounter Django] - (II) database configuration
79. Word search [DFS + backtracking visit + traversal starting point]
c语言学习
CS5268优势替代AG9321MCQ Typec多合一扩展坞方案
机器学习—性能度量
shell脚本导入存储过程到数据库
What are the solutions for session sharing of highly paid programmers & interview questions series 118?
There are still many things to be done in the second half of the year
SSO and JWT good article sorting
Localtime can't re-enter. It's a pit
Tencent security released the white paper on BOT Management | interpreting BOT attacks and exploring ways to protect
SQLAlchemy在删除有外键约束的记录时,外键约束未起作用,何解?
79. 单词搜索【dfs + 回溯visit + 遍历起点】
codeforces -- 4B. Before an Exam
Operator-1 first acquaintance with operator