MySQL Backup--Xtrabackup备份限速问题

在innobackupex 2.4版本中,有两个参数用来限制备份速度:

--throttle=#        
This option specifies a number of I/O operations (pairs
of read+write) per second.  It accepts an integer
argument.  It is passed directly to xtrabackup's
--throttle option.

--parallel=#       
On backup, this option specifies the number of threads
the xtrabackup child process should use to back up files
concurrently.  The option accepts an integer argument. It
is passed directly to xtrabackup's --parallel option. See
the xtrabackup documentation for details.

在percoan官方网站上对throttle参数有如下解释:

Although xtrabackup does not block your database’s operation, 
any backup can add load to the system being backed up. On systems 
that do not have much spare I/O capacity, it might be helpful to 
throttle the rate at which xtrabackup reads and writes data. 
You can do this with the xtrabackup --throttle option. This option 
limits the number of chunks copied per second. The chunk size is 10 MB.
https://www.percona.com/doc/percona-xtrabackup/2.4/advanced/throttling_backups.html

如果想将备份速度控制在50MB/s以下的话,那么throttle参数需要设置为5,使用该参数备份开始后IO使用情况为:

备份进程一直在写xtrabackup_logfile文件,如果备份实例的数据操作较多时,会导致备份进程一直处于该状态无法继续后面操作。

PS: 备份目录下xtrabackup_logfile文件的增长速度和参数throttle密切相关。

在备份实例停止全部操作情况,使用throttle=5进行备份,备份进行执行10分钟还在处理xtrabackup_logfile文件,备份效率无法保证。

调整为throttle=10后,备份过程中期IO使用情况为:

10*10MB/S=100MB/S=102400KB/S,证明throttle=10的确有效。

参数parallel使用多个进程来备份数据文件,在磁盘速度够快情况下,parallel能有效提升备份效率,但无法进行限速操作。

 

======================================================================================

由于参数throttle设置较低会导致无法正常备份,而设置较高又无法起到限速目的,因此考虑使用pv方式来限速。

PV 由Andrew Wood 开发,是 Pipe Viewer 的简称,经过管道显现数据处理进展的信息,控制管道数据的流入流出速度,就到控制备份的速度。

为验证pv限速和对比stream备份和普通备份的差距,设计下面三种测试方案:

方案1:使用stream=tar流时备份+使用tar -x解压到本地+使用PV限制速度200M(下图红色框标识)
方案2:不使用stream流式备份+备份本地+不限制速度(下图绿色框标识)
方案3:使用stream=tar流时备份+使用tar -x解压到本地+不限制速度(下图黄色框标识)

测试脚本为:

## 使用stream=tar流时备份
## 使用tar -x解压到本地
## 使用PV限制速度200M
innobackupex \
--defaults-file="/export/servers/mysql/etc/my.cnf" \
--host="localhost" \
--port=3358 \
--user='root' \
--password='root_password' \
--stream=tar \
"/export/bak/tmp/" |pv -q -L200m | tar -x

## 不使用stream流式备份
## 不限制速度
innobackupex \
--defaults-file="/export/servers/mysql/etc/my.cnf" \
--host="localhost" \
--port=3358 \
--user='root' \
--password='root_password' \
"/export/bak/full/"

## 使用stream=tar流时备份
## 使用tar -x解压到本地
## 不限制速度
innobackupex \
--defaults-file="/export/servers/mysql/etc/my.cnf" \
--host="localhost" \
--port=3358 \
--user='root' \
--password='root_password' \
--stream=tar \
"/export/bak/tmp/" | tar -x

 

备份对CPU的影响:

备份对IO读写次数的影响:

备份对IO读写速度的影响:

 

对比发现:

1、使用pv命令可以有效限制备份读写速度,但不能精确限制读写速度(限速200MB/S,实际速度170MB/S)

2、使用stream压缩+解压进行备份时,CPU有轻微增长,但影响并不明显。

3、在不限速情况下,使用stream压缩+解压的备份效率远低于普通备份(上面测试环境下接近差一倍)

4、使用stream压缩+解压进行备份时,可以增减备份线程parallel来提高备份效率。

 

posted @ 2019-06-06 13:38  TeyGao  阅读(2215)  评论(0编辑  收藏  举报