压缩方式传输文件效率对比

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、Gzip压缩方式传输

在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倍

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容