zoukankan      html  css  js  c++  java
  • Linux下将两个10G的文件打包成一个文件需要多久

    Linux下将两个10G的文件打包成一个文件需要多久 | 公云网博客

    Linux下将两个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,这是要大把花银子的。

  • 相关阅读:
    mojo 接口示例
    MojoliciousLite: 实时的web框架 概述
    接口返回json
    centos 6.7 perl 版本 This is perl 5, version 22 安装DBI DBD
    centos 6.7 perl 5.22 安装DBD 需要使用老的perl版本
    商业智能改变汽车行业
    商业智能改变汽车行业
    读MBA经历回顾(上)目的决定手段——北漂18年(48)
    perl 升级到5.20版本
    Group Commit of Binary Log
  • 原文地址:https://www.cnblogs.com/lexus/p/2876677.html
Copyright © 2011-2022 走看看