panmeng
作者panmeng·2020-06-04 16:59
系统工程师·成都农商银行

使用压缩对SCP传输文件进行性能优化

字数 1823阅读 7371评论 0赞 1
1、测试环境:
  • 拓扑host1---wlan---host2(192.168.124.25)
  • 网速不稳定,20Mbps-40Mbps
  • 测试文件195MB
  • 主要瓶颈为网络,是否清理cache关系不大
2、Scp复制

确认测试文件大小及md5校验

# du -sm testfile
195 testfile
# md5sum testfile
9fad1b628cb4919d5977ccbfce189c37 testfile

清空缓存

# echo 3> /proc/sys/vm/drop_caches

测试直接使用scp复制的速度,耗时52秒

# time scp testfile root@192.168.124.25:/tmp/
testfile 100% 183MB 3.6MB/s 00:51
real 0m52.030s
user 0m0.197s
sys 0m0.809s

清空缓存

# echo 3> /proc/sys/vm/drop_caches

再次测试直接使用scp复制的速度,耗时80秒

# time scp testfile root@192.168.124.25:/tmp/
testfile 100% 183MB 2.3MB/s 01:20
real 1m20.740s
user 0m0.174s
sys 0m0.802s

在host2上验证文件MD5,可以看到md5校验和一致

# ssh root@192.168.124.25 "md5sum /tmp/testfile"
9fad1b628cb4919d5977ccbfce189c37 /tmp/testfile
3、压缩方式传输

在host2上删除测试文件testfile

# ssh root@192.168.124.25 "rm -f /tmp/testfile"

清空缓存

# echo 3> /proc/sys/vm/drop_caches

测试使用gzip压缩的方式传输文件,可以看到md5校验和一致,耗时6秒

# time gzip -c -1 testfile | ssh root@192.168.124.25 "gzip -d - > /tmp/testfile"
real 0m5.907s
user 0m1.518s
sys 0m0.270s
# ssh root@192.168.124.25 "md5sum /tmp/testfile"
9fad1b628cb4919d5977ccbfce189c37 /tmp/testfile

再次测试使用gzip压缩的方式传输文件,可以看到md5校验和一致,耗时3.3秒

# ssh root@192.168.124.25 "rm -f /tmp/testfile"
# echo 3> /proc/sys/vm/drop_caches
# time gzip -c -1 testfile | ssh root@192.168.124.25 "gzip -d - > /tmp/testfile"
real 0m3.316s
user 0m1.391s
sys 0m0.296s
# ssh root@192.168.124.25 "md5sum /tmp/testfile"
9fad1b628cb4919d5977ccbfce189c37 /tmp/testfile
4、添加ssh参数实现压缩

直接增加ssh参数Compression=yes,可以更简单的实现压缩传输,但是不能像gzip一样灵活配置压缩级别

# ssh root@192.168.124.25 "rm -f /tmp/testfile"
# echo 3 > /proc/sys/vm/drop_caches
# time scp -o Compression=yes testfile root@192.168.124.25:/tmp/
testfile 100% 183MB 43.6MB/s 00:04
real 0m4.696s
user 0m1.261s
sys 0m3.193s
# ssh root@192.168.124.25 "md5sum /tmp/testfile"
9fad1b628cb4919d5977ccbfce189c37 /tmp/testfile
5、结论

在20-40Mbps不稳定网速下,使用压缩的方式,效率比直接scp高15倍

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

1

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关问题

相关资料

X社区推广