【转】打包2个10g文件 测试


微博上kevin_prajna提了一个问题:“求Linux下一打包工具,需求:能把两个10G的文件打包成一个文件,时间在1分钟之内能接受!”。

暂且作答一下吧。首先问题是求解工具,那么我们忽略IO问题,采用内存盘来解决, 在公司一台128G内存的机器上:

mkdir /mnt/test
mount -t ramfs none /mnt/test
cd /mnt/test
生成一个小脚本,生成两个10G的文件:

#!/bin/bash
for (( i = 0; i < 2; i++)); do
echo $i
    dd if=/dev/zero of=file$i.bin bs=1M count=10000
done;
生成测试文件:

time ./test.sh <<<
0
10000+0 records in
10000+0 records out
10485760000 bytes (10 GB) copied, 4.78903 s, 2.2 GB/s
1
10000+0 records in
10000+0 records out
10485760000 bytes (10 GB) copied, 4.92947 s, 2.1 GB/s
./test.sh 0.00s user 9.68s system 99% cpu 9.731 total
测试结果,生成两个10G文件,消耗了9.731秒

采用tar打包工具测试:

time tar cvf out.bin file* <<<
file0.bin
file1.bin
tar cvf out.bin file* 0.40s user 13.90s system 99% cpu 14.353 total
采用 tar打包这两个文件,并且写入 out.bin文件,消耗了 14.353秒, 完全满足kevin_prajna的要求。

然后我们用cpio来测试,由于cpio对10G这样的文件打包有bug,会报错,所以我们用20个1G文件测试:

#!/bin/bash
for (( i = 0; i < 20; i++)); do
echo $i
    dd if=/dev/zero of=file$i.bin bs=1M count=1000
done;
生成20个1G测试文件,用了 9.806秒

使用tar对这20个1G文件打包,用了13.800 秒

cpio的测试结果:

# time ls file*|cpio -o > out.bin                                                                                                                                           <<<
40960002 blocks
ls --color=tty file*  0.00s user 0.00s system 0% cpu 0.002 total
cpio -o > out.bin  6.31s user 37.61s system 99% cpu 44.029 total
cpio打包这20个1G文件消耗了44.029秒,速度相对tar,还是慢了好多。

测试环境:

Dell R710, 2*Xeon E5620, 128G RAM
OS: Ubuntu 12.04 x86_64

从上面也可以看出,现在CPU和工具是很强悍的,弱爆的是磁盘IO,这是要大把花银子的。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM