Home Database Mysql Tutorial MySQL多线程同步MySQL-Transfer介绍

MySQL多线程同步MySQL-Transfer介绍

Jun 07, 2016 pm 04:14 PM
mysql introduce Synchronize thread

一、 关于 Transfer MySQL-Transefer(下称Transfer)是一个基于MySQL+patch后得到的主从同步工具。 其主要目的是为了解决原生版本的主从同步里,从库是单线程apply主库的binlog,导致的延迟。 最近完成测试的版本将multi-master (by P.Linux)合并到Transfer

一、关于Transfer

MySQL-Transefer(下称Transfer)是一个基于MySQL+patch后得到的主从同步工具。
其主要目的是为了解决原生版本的主从同步里,从库是单线程apply主库的binlog,导致的延迟。

最近完成测试的版本将multi-master (by P.Linux)合并到Transfer中并针对支付宝的应用需求做了定制性能改进。

这里做一个已经完成的完整功能介绍。

二、总体结构

 
 

说明:
1、Transfer可以注册成多个Master的从库
2、Transfer接收多个Master传入的binlog后将更新执行到Slave上
3、Transfer本地没有数据

如果你没有多主的需求,那结构就是Master -> Transfer -> Slave.

三、内部结构

      既然是单线程造成的主从延迟,提升就需要用多线程来实现。

  我们来看单主情况下的内部实现。

 

说明:左上角是Master, 右上角是Transfer,下面是Slave。

 

四、增加参数及对应说明

在my.cnf中新增如下几个参数:

remote_slave_hostname = Ip of Slave
remote_slave_username = root
remote_slave_password = root
remote_slave_port = Port of Slave
stop_slave_on_error = 1
remote_table_maps_file = ./table_maps
transfer_slave_thread = 10 

说明:

1、  前四个是目标slave库的认证信息
2、  Stop_slave_on_error 一般建议配置为1,表示只要有一个线程执行出错,所有slave_io_thread都停止

3、  remote_table_maps_file路径指向本地文件,文件中每行格式为 “表1 表2”,表示在Transfer做同步时,将Master上所有对表1的操作都更新到表2.

4、  transfer_slave_thread是一个只读参数,控制Transfer有多少个线程做并发更新(若为1则表示串行更新,性能与官方版本相同)。一般建议配置为系统核数2倍。

 

 

五、一些说明

1、由于Transfer是在MySQL基础上打的patch,因此支持几乎所有MySQL的监控命令,你原来加在Slave上的监控,可以直接改到Transfer上。

2、             一般我们将Transfer和Slave放在同一个机器上(等于是装两个MySQL,一个是Transfer,一个是真正的slave)

3、             Transfer按照表名hash将不同表的更新分配到不同的线程,因此在多表环境下才能看得到性能提升

4、             Master的binlog格式必须设置成row

5、             若需要用到多个Master,给每个Master命令一个channel,命令 序列为 change master channel1 to master_log_file=xxx…… ; start slave channel1; 可以单独对一个chanel执行start\stop等命令

6、             若只需要一个master,则语法格式不变

 六、性能效果

测试场景如下,在Master上的16个表并发分别插入10w行。期间先停止同步。插入完成后,再分别测试直接用原生版本主从和Transfer的性能。

主库插入耗时66.1s 。

 

耗时

平均tps

MySQL主从

363s

4402/s

Transfer同步

66s

24242/s

 

七、Patch应用

下载地址。 基于5.1.48,   patch –p0

示例my.cnf 从此下载,记得修改程序安装目录。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL for Beginners: Getting Started with Database Management MySQL for Beginners: Getting Started with Database Management Apr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Apr 18, 2025 am 08:42 AM

When developing an e-commerce website using Thelia, I encountered a tricky problem: MySQL mode is not set properly, causing some features to not function properly. After some exploration, I found a module called TheliaMySQLModesChecker, which is able to automatically fix the MySQL pattern required by Thelia, completely solving my troubles.

See all articles