数据备份加密算法性能对比

数据目录大小:

56G ./data

不加密:

[root@db100 mysql]# time innobackupex --defaults-file=/home/mysql/etc/my.cnf --user=user --password=password --host=127.0.0.1 --port=3306 --slave-info --stream=tar --tmpdir=/mysql/bak /mysql/bak 2>sdfs_bak.log| zstd -T4 - > /mysql/bak/mysqlbackup_`hostname`.tar.zstd

real 2m51.668s
user 6m3.056s
sys 1m5.078s

[root@db100 mysql]# time cat /mysql/bak/mysqlbackup_`hostname`.tar.zstd| zstd -d | tar x -C /mysql/data2/

real 4m28.512s
user 2m16.214s
sys 1m58.708s

aes-128-cbc:

[root@db100 mysql]# time innobackupex --defaults-file=/home/mysql/etc/my.cnf --user=user --password=password --host=127.0.0.1 --port=3306 --slave-info --stream=tar --tmpdir=/mysql/bak /mysql/bak 2>sdfs_bak.log| zstd -T4 - | /home/openssl/bin/openssl enc -aes-128-cbc -pbkdf2 -pass pass:86C63180C2806ED1F47B859DE501215B -out /mysql/bak/mysqlbackup_`hostname`.tar.zstd.aes

real 3m0.913s
user 6m22.789s
sys 1m11.888s

[root@db100 mysql]# time cat /mysql/bak/mysqlbackup_`hostname`.tar.zstd.aes| /home/openssl/bin/openssl enc -aes-128-cbc -pbkdf2 -d -pass pass:86C63180C2806ED1F47B859DE501215B | zstd -d | tar x -C /mysql/data2/

real 4m30.357s
user 2m19.977s
sys 2m14.951s

sm4:

[root@db100 mysql]# time innobackupex --defaults-file=/home/mysql/etc/my.cnf --user=user --password=password --host=127.0.0.1 --port=3306 --slave-info --stream=tar --tmpdir=/mysql/bak /mysql/bak 2>sdfs_bak.log| zstd -T4 - | /home/openssl/bin/openssl enc -sm4 -pbkdf2 -pass pass:86C63180C2806ED1F47B859DE501215B -out /mysql/bak/mysqlbackup_`hostname`.tar.zstd.sm4

real 4m33.858s
user 8m3.212s
sys 1m11.111s

[root@db100 mysql]# time cat /mysql/bak/mysqlbackup_`hostname`.tar.zstd.sm4| /home/openssl/bin/openssl enc -sm4 -pbkdf2 -d -pass pass:86C63180C2806ED1F47B859DE501215B | zstd -d | tar x -C /mysql/data2/

real 6m10.457s
user 4m8.749s
sys 2m21.759s

sm4-cbc:

[root@db100 mysql]# time innobackupex --defaults-file=/home/mysql/etc/my.cnf --user=user --password=password --host=127.0.0.1 --port=3306 --slave-info --stream=tar --tmpdir=/mysql/bak /mysql/bak 2>sdfs_bak.log| zstd -T4 - | /home/openssl/bin/openssl enc -sm4-cbc -pbkdf2 -pass pass:86C63180C2806ED1F47B859DE501215B -out /mysql/bak/mysqlbackup_`hostname`.tar.zstd.sm4cbc

real 4m33.006s
user 8m3.680s
sys 1m12.156s

[root@db100 mysql]# time cat /mysql/bak/mysqlbackup_`hostname`.tar.zstd.sm4cbc| /home/openssl/bin/openssl enc -sm4-cbc -pbkdf2 -d -pass pass:86C63180C2806ED1F47B859DE501215B | zstd -d | tar x -C /mysql/data2/

real 6m9.693s
user 4m8.843s
sys 2m21.738s

对比:

加密方式不加密aes-128-cbcsm4sm4-cbc
备份时间(s)172181274273
备份时间增加5.23%59.30 %58.72%
恢复时间(s)269270370370
恢复时间增加0.37 %37.55 %37.55 %

1、使用aes-128-cbc算法加密对备份以及恢复性能影响都非常小,分别为约5.23%、不到0.37%;sm4、sm4-cbc备份时间延长约59%,恢复时间延长37.55%

2、aes加密CPU占用约20%;sm4、sm4-cbc加密CPU占用约50%,同时会拉低压缩与备份进程性能(216%->142%,38%->23%)

3、备份文件大小不同算法之间没有差别,都为7.4G

4、需要升级OpenSSL到1.1.1版本才支持sm4算法