>  기사  >  데이터 베이스  >  mydumper 및 myloader의 내보내기 및 가져오기 속도를 높입니다.

mydumper 및 myloader의 내보내기 및 가져오기 속도를 높입니다.

黄舟
黄舟원래의
2017-02-13 11:04:181616검색

Mydumper와 myloader는 멀티스레드 내보내기 및 가져오기를 사용하는 뛰어난 타사 mysql 데이터베이스 논리적 백업 및 복구 도구입니다. 이는 mysqldump의 단일 스레드의 단점을 보완합니다. 이 문서에서는 참고용으로 mydumper 및 myloader 내보내기 및 가져오기 속도를 높이는 방법을 설명합니다.

mydumper 및 myloader에 대한 기타 사항은 다음을 참조하세요.
Mydumper 설치 및 설치 실패 요약
Mydumper 백업 mysql 데이터베이스 예시
myloader 복원 mysql 데이터베이스 예시


1. MyIsam 엔진 기반으로 내보내기 및 가져오기
a. 청크로 가져왔습니다
[root@GZAPP tmp]# mydumper -u inno -p xxx -B bsom -T tb_access_log -o /backup/tmp/
[root@GZAPP tmp]# ls -hltr ### 내보낸 데이터 파일은 단일 파일이며 크기는 2.6GB
총 2.6G
-rw-r--r-- 1 루트 루트 1.6K Jul 24 08:51 bsom.tb_access_log-schema.sql
-rw-r-- r-- 1 루트 루트 214 7월 24일 08:52 메타데이터
-rw-r--r-- 1 루트 루트 2.6G 7월 24일 08:52 bsom.tb_access_log.sql

###기본 스레드 수를 기준으로 가져오고 트랜잭션당 쿼리 수를 10000으로 설정합니다. 테이블이 myisam 엔진이므로 이 매개변수는 실제로 현재 거의 사용되지 않습니다. 🎜>

[root@GZAPP tmp]# myloader -u inno -p xxx -B tempdb -d /backup/tmp -v 3 -q 10000
[root@GZAPP tmp]# myloader -u inno -p xxx -B tempdb -d /backup/tmp -v 3 -q 10000
** Message: 4 threads created
** Message: Creating table `tempdb`.`tb_access_log`
** Message: Thread 4 shutting down
** Message: Thread 1 restoring `bsom`.`tb_access_log` part 0
** Message: Thread 3 shutting down
** Message: Thread 2 shutting down


root@localhost[tempdb]> +--------- -+---------+----------+---------+------ ---+--------- +---------+--------------- --------------- ---------+
| 사용자 | db 명령 |
+- --------+------ ---+----------+---------+---------+- -----+--------- ------------ ------------ ----- -+
| 4452079 | tempdb | 초기화 | 프로세스 목록 | | tempdb | NULL |
| 4453794 | INSERT INTO `tb_access>+-- ----+---------+---- ------+---------+---------+---- ---+---------+------ ------------------ ------+

### 위의 스레드 수를 보면 삽입 작업을 실행하는 단일 스레드만 있음을 알 수 있습니다.


b. 테이블 포인트 블록 내보내기 및 가져오기

###다음 예에서는 500MB가 사용됩니다. 청킹


[root@GZAPP tmp]# mydumper -u inno -p xxx -B bsom -T tb_access_log -F 500 -o /backup/tmp/
[root@GZAPP tmp]# ls -hltr
total 2.6G      
-rw-r--r-- 1 root root 1.6K Jul 24 08:21 bsom.tb_access_log-schema.sql
-rw-r--r-- 1 root root 478M Jul 24 08:21 bsom.tb_access_log.00001.sql
-rw-r--r-- 1 root root 478M Jul 24 08:21 bsom.tb_access_log.00002.sql
-rw-r--r-- 1 root root 478M Jul 24 08:21 bsom.tb_access_log.00003.sql
-rw-r--r-- 1 root root 478M Jul 24 08:21 bsom.tb_access_log.00004.sql
-rw-r--r-- 1 root root 478M Jul 24 08:22 bsom.tb_access_log.00005.sql
-rw-r--r-- 1 root root  214 Jul 24 08:22 metadata
-rw-r--r-- 1 root root 241M Jul 24 08:22 bsom.tb_access_log.00006.sql

###위에서 볼 수 있듯이 대형 테이블 tb_access_log는 500M 가까이 여러 파일로 나누어져 있습니다

[root@GZAPP tmp]# myloader -u inno -p xxx -B tempdb -t 6 -d /backup/tmp -v 3
** Message: 6 threads created
** Message: Creating database `tempdb`
** Message: Creating table `tempdb`.`tb_access_log`
** Message: Thread 1 restoring `bsom`.`tb_access_log` part 3
** Message: Thread 2 restoring `bsom`.`tb_access_log` part 5
** Message: Thread 5 restoring `bsom`.`tb_access_log` part 4
** Message: Thread 3 restoring `bsom`.`tb_access_log` part 6
** Message: Thread 4 restoring `bsom`.`tb_access_log` part 1
** Message: Thread 6 restoring `bsom`.`tb_access_log` part 2

#在下面的processlist可以看到,存在表级锁等待
+---------+-------+-----------+---------+---------+--------+-----------------------------+------------------------------------------------+
| Id      | User  | Host      | db      | Command | Time   | State                       | Info                                           |
+---------+-------+-----------+---------+---------+--------+-----------------------------+------------------------------------------------+
| 4452079 | root  | localhost | bsom    | Query   |      0 | init                        | show processlist                               |
| 4452167 | inno  | localhost | tempdb  | Sleep   |    769 |                             | NULL                                           |
| 4452168 | inno  | localhost | tempdb  | Query   |     36 | update                      | INSERT INTO `tb_access_log` VALUES (6367402,"0,|
| 4452169 | inno  | localhost | tempdb  | Query   |     21 | Waiting for table level lock| INSERT INTO `tb_access_log` VALUES (12593865," |
| 4452170 | inno  | localhost | tempdb  | Query   |     26 | Waiting for table level lock| INSERT INTO `tb_access_log` VALUES (15643029,""|
| 4452171 | inno  | localhost | tempdb  | Query   |      6 | Waiting for table level lock| INSERT INTO `tb_access_log` VALUES (173947,"70 |
| 4452172 | inno  | localhost | tempdb  | Query   |     15 | Waiting for table level lock| INSERT INTO `tb_access_log` VALUES (9490507,"7 |
| 4452173 | inno  | localhost | tempdb  | Query   |     30 | Waiting for table level lock| INSERT INTO `tb_access_log` VALUES (3271602,"4 |
+---------+---------+-----------+---------+---------+--------+-----------------------------+----------------------------------------------+


c、调整myisam有关参数后导入

[root@GZ-APP-BAK01 tmp]# time myloader -u innobk -p InnoBK -B tempdb -t 6 -d /backup/tmp -v 3
** Message: 6 threads created
** Message: Creating table `tempdb`.`tb_mobile_access_log`
** Message: Thread 1 restoring `blossom`.`tb_mobile_access_log` part 3
** Message: Thread 6 restoring `blossom`.`tb_mobile_access_log` part 6
** Message: Thread 2 restoring `blossom`.`tb_mobile_access_log` part 5
** Message: Thread 3 restoring `blossom`.`tb_mobile_access_log` part 4
** Message: Thread 4 restoring `blossom`.`tb_mobile_access_log` part 1
** Message: Thread 5 restoring `blossom`.`tb_mobile_access_log` part 2
** Message: Thread 6 shutting down
** Message: Thread 5 shutting down
** Message: Thread 1 shutting down
** Message: Thread 2 shutting down
** Message: Thread 4 shutting down
** Message: Thread 3 shutting down


real    266m28.903s
user    0m6.008s
sys     0m1.681s

###调整以下相关参数,后尝试再次导入,
concurrent_insert  AUTO 改成 ALWAYS
bulk_insert_buffer_size 8388608 改成 256M
myisam_sort_buffer_size 67108864 改成 128M

[root@GZ-APP-BAK01 tmp]# time myloader -u innobk -p InnoBK -B tempdb -t 6 -o -d /backup/tmp -v 3
** Message: 6 threads created
** Message: Dropping table (if exists) `tempdb`.`tb_mobile_access_log`
** Message: Creating table `tempdb`.`tb_mobile_access_log`
** Message: Thread 1 restoring `blossom`.`tb_mobile_access_log` part 3
** Message: Thread 2 restoring `blossom`.`tb_mobile_access_log` part 6
** Message: Thread 3 restoring `blossom`.`tb_mobile_access_log` part 5
** Message: Thread 4 restoring `blossom`.`tb_mobile_access_log` part 4
** Message: Thread 6 restoring `blossom`.`tb_mobile_access_log` part 1
** Message: Thread 5 restoring `blossom`.`tb_mobile_access_log` part 2
** Message: Thread 2 shutting down
** Message: Thread 1 shutting down
** Message: Thread 6 shutting down
** Message: Thread 5 shutting down
** Message: Thread 3 shutting down
** Message: Thread 4 shutting down


real    253m42.460s   ###此时导入时间并无明显减少
user    0m5.924s
sys     0m1.637s


2、基于innodb引擎的导出导入
a、表未分块导出,数据文件大小为3.9GB

[root@GZAPP tmp]# ls -hltr
total 3.9G
-rw-r--r-- 1 root root 1.8K Jul 24 00:09 bscom.tb_message-schema.sql
-rw-r--r-- 1 root root 3.9G Jul 24 00:25 bscom.tb_message.sql
-rw-r--r-- 1 root root  215 Jul 24 09:14 metadata


###下面使用6个线程导入,实际上可以看到,只有1个线程在工作,因为数据文件只有1个

[root@GZAPP tmp]# myloader -u inno -p xxx -B tempdb -t 6 -d /backup/tmp -v 3
** Message: 6 threads created
** Message: Creating table `tempdb`.`tb_message`
** Message: Thread 1 restoring `bscom`.`tb_message` part 0
** Message: Thread 5 shutting down
** Message: Thread 2 shutting down
** Message: Thread 6 shutting down
** Message: Thread 3 shutting down
** Message: Thread 4 shutting down



b、表分块导出

[root@GZAPP tmp]# mydumper -u inno -p xxx -B bscom -T tb_message -F 500 -o /backup/tmp/
[root@GZAPP tmp]# ls -hltr
total 3.9G
-rw-r--r-- 1 root root 1.8K Jul 24 09:55 bscom.tb_message-schema.sql
-rw-r--r-- 1 root root 478M Jul 24 09:55 bscom.tb_message.00001.sql
-rw-r--r-- 1 root root 478M Jul 24 09:55 bscom.tb_message.00002.sql
-rw-r--r-- 1 root root 478M Jul 24 09:55 bscom.tb_message.00003.sql
-rw-r--r-- 1 root root 478M Jul 24 09:55 bscom.tb_message.00004.sql
-rw-r--r-- 1 root root 478M Jul 24 09:55 bscom.tb_message.00005.sql
-rw-r--r-- 1 root root 478M Jul 24 09:55 bscom.tb_message.00006.sql
-rw-r--r-- 1 root root 478M Jul 24 09:55 bscom.tb_message.00007.sql
-rw-r--r-- 1 root root 481M Jul 24 09:55 bscom.tb_message.00008.sql
-rw-r--r-- 1 root root  135 Jul 24 09:55 metadata
-rw-r--r-- 1 root root  93M Jul 24 09:55 bscom.tb_message.00009.sql


###下面尝试使用6线程导入,可以看到有6个线程在并发导入

[root@GZAPP tmp]# myloader -u inno -p xxx -B tempdb -t 6 -d /backup/tmp/ -v 3
** Message: 6 threads created
** Message: Creating database `tempdb`
** Message: Creating table `tempdb`.`tb_message`
** Message: Thread 2 restoring `bscom`.`tb_message` part 5
** Message: Thread 1 restoring `bscom`.`tb_message` part 9
** Message: Thread 3 restoring `bscom`.`tb_message` part 1
** Message: Thread 4 restoring `bscom`.`tb_message` part 8
** Message: Thread 5 restoring `bscom`.`tb_message` part 4
** Message: Thread 6 restoring `bscom`.`tb_message` part 6
** Message: Thread 1 restoring `bscom`.`tb_message` part 7
** Message: Thread 6 restoring `bscom`.`tb_message` part 3
** Message: Thread 2 restoring `bscom`.`tb_message` part 2
** Message: Thread 3 shutting down
** Message: Thread 5 shutting down
** Message: Thread 4 shutting down
** Message: Thread 1 shutting down
** Message: Thread 2 shutting down
** Message: Thread 6 shutting down



3、小结
a、mydumper在导出的时候可以根据服务器可用资源来合理地设置线程数。
b、mydumper在导出的时候尽可能地指定chunk-filesize或者rows参数以分块导出。
c、myloader在针对myisam引擎时建议调整相关参数至合理值以提高无法提高性能,主要是表级锁的问题。
d、myloader在针对innodb引擎时建议调整参数至合理值以提高性能,如以下参数等:
 

 innodb_buffer_pool_size
  innodb_flush_log_at_trx_commit
  innodb_log_buffer_size

e、通过使用分块导出与导入可以显著利用并发来加快inndbo表导入。  
f、注意mydumper导出时不会导出存储过程,函数,触发器等。

以上就是加快mydumper与myloader导出导入的内容,更多相关内容请关注PHP中文网(www.php.cn)!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.