学习Linux系统时都会学习这么几个压缩工具:gzip、bzip2、zip、xz,以及相关的解压工具。关于这几个工具的使用和相互之间的压缩比以及压缩时间对比可以看:Linux中归档压缩工具学习

那么Pigz是什么呢?简单的说,就是支持并行压缩的gzip。Pigz默认用当前逻辑cpu个数来并发压缩,无法检测个数的话,则默认并发8个线程,也可以使用-p指定线程数。需要注意的是其CPU使用比较高。

官网:http://zlib.net/pigz

废话不多说,开始测试。

 
1
$ yum install pigz
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$ pigz --help
Usage: pigz [options] [files ...]
  will compress files in place, adding the suffix '.gz'.  If no files are
  specified, stdin will be compressed to stdout.  pigz does what gzip does,
  but spreads the work over multiple processors and cores when compressing.
 
Options:
  -0 to -9, -11        Compression level (11 is much slower, a few % better)
  --fast, --best       Compression levels 1 and 9 respectively
  -b, --blocksize mmm  Set compression block size to mmmK (default 128K)
  -c, --stdout         Write all processed output to stdout (won't delete)
  -d, --decompress     Decompress the compressed input
  -f, --force          Force overwrite, compress .gz, links, and to terminal
  -F  --first          Do iterations first, before block split for -11
  -h, --help           Display a help screen and quit
  -i, --independent    Compress blocks independently for damage recovery
  -I, --iterations n   Number of iterations for -11 optimization
  -k, --keep           Do not delete original file after processing
  -K, --zip            Compress to PKWare zip (.zip) single entry format
  -l, --list           List the contents of the compressed input
  -L, --license        Display the pigz license and quit
  -M, --maxsplits n    Maximum number of split blocks for -11
  -n, --no-name        Do not store or restore file name in/from header
  -N, --name           Store/restore file name and mod time in/from header
  -O  --oneblock       Do not split into smaller blocks for -11
  -p, --processes n    Allow up to n compression threads (default is the
                       number of online processors, or 8 if unknown)
  -q, --quiet          Print no messages, even on error
  -r, --recursive      Process the contents of all subdirectories
  -R, --rsyncable      Input-determined block locations for rsync
  -S, --suffix .sss    Use suffix .sss instead of .gz (for compression)
  -t, --test           Test the integrity of the compressed input
  -T, --no-time        Do not store or restore mod time in/from header
  -v, --verbose        Provide more verbose output
  -V  --version        Show the version of pigz
  -z, --zlib           Compress to zlib (.zz) instead of gzip format
  --                   All arguments after "--" are treated as files

原目录大小

 
1
2
$ du -sh /tmp/hadoop
2.3G    /tmp/hadoop

使用gzip压缩(1个线程)

 
1
2
3
4
5
6
7
8
9
# 压缩耗时;
$ time tar -zvcf hadoop.tar.gz /tmp/hadoop
real 0m49.935s
user 0m46.205s
sys 0m3.449s
 
# 压缩大小;
$ du -sh hadoop.tar.gz
410M hadoop.tar.gz

解压gzip压缩文件

 
1
2
3
4
5
$ time tar xf hadoop.tar.gz
 
real    0m17.226s
user    0m14.647s
sys     0m4.957s

使用pigz压缩(4个线程)

 
1
2
3
4
5
6
7
8
9
# 压缩耗时;
$ time tar -cf - /tmp/hadoop | pigz -p 4 > hadoop.tgz
real 0m13.596s
user 0m48.181s
sys 0m2.045s
 
# 压缩大小;
$ du -sh hadoop.tgz
411M hadoop.tgz

解压pigz文件

 
1
2
3
4
5
$ time pigz -p 4 -d hadoop.tgz                      
 
real    0m17.508s
user    0m12.973s
sys     0m5.037s

可以看出pigz时间上比gzip快了三分之二还多,但CPU消耗则是gzip的好几倍,我这里只是4个线程的虚拟机,当然pigz的CPU使用率也是很可观的哦,基本100%了。所以在对压缩效率要求较高、但对短时间内CPU消耗较高不受影响的场景,使用pigz非常合适。

当然pigz也不是随着线程的增加速度就越快,也有一个瓶颈区域,网上有人对比了一下:并发8线程对比4线程提升41.2%,16线程对比8线程提升27.9%,32线程对比16线程提升3%。可以看出线程数越高速度提升就越慢了。更多的可以自己测试。

转自

Linux命令:pigz多线程压缩工具 – 运维那点事
http://www.ywnds.com/?p=10332

参考

tar+pigz+ssh实现大数据压缩传输 - 夏天公子 - 博客园
https://www.cnblogs.com/chenglee/p/7161274.html

Linux命令:pigz多线程压缩工具【转】的更多相关文章

  1. linux使用pigz多线程压缩

    因为tar zip是单线程的压缩,压缩起来很慢,这个使用使用pigz工具辅助就会使用多线程了. 安装 sudo apt install pigz 压缩 tar cvf - test.txt | pig ...

  2. Linux命令行–更多bash shell命令(转)

    4.1.1 探查程序 ps 命令 默认情况下,ps命令只会显示运行在当前控制台下的属于当前用户进程的进程 显示的当前进程的项目 进程号 运行在哪个终端(tty) 进程占用的CPU时间 Linux系统支 ...

  3. 如何利用多核CPU来加速你的Linux命令 — awk, sed, bzip2, grep, wc等(转)

    你是否曾经有过要计算一个非常大的数据(几百GB)的需求?或在里面搜索,或其它操作——一些无法并行的操作.数据专家们,我是在对你们说.你可能有一个4核或更多核的CPU,但我们合适的工具,例如 grep, ...

  4. <转>如何利用多核CPU来加速你的Linux命令 — awk, sed, bzip2, grep, wc等

    原文链接:http://www.vaikan.com/use-multiple-cpu-cores-with-your-linux-commands/ 你是否曾经有过要计算一个非常大的数据(几百GB) ...

  5. 利用多核来加速Linux命令行

    本文转载自 多核CPU来加速 awk, sed, bzip2, grep, wc等,如需查看原文,请点此链接进入. -------------------------------我是分割线 开始 -- ...

  6. 如何利用多核CPU来加速你的Linux命令

    原文出处: rankfocus   译文出处: 外刊IT评论 你是否曾经有过要计算一个非常大的数据(几百GB)的需求?或在里面搜索,或其它操作——一些无法并行的操作.数据专家们,我是在对你们说.你可能 ...

  7. 转摘--如何利用多核CPU来加速你的Linux命令 — awk, sed, bzip2, grep, wc等

    http://www.vaikan.com/use-multiple-cpu-cores-with-your-linux-commands/ 你是否曾经有过要计算一个非常大的数据(几百GB)的需求?或 ...

  8. 《转》Linux下的多线程编程

    原地址:http://linux.chinaunix.net/doc/program/2001-08-11/642.shtml 1 引言 线程(thread)技术早在60年代就被提出,但真正应用多线程 ...

  9. Linux命令 文件压缩及压缩命令

    gzip [功能说明] 文件的压缩 #gizp属于GNU软件,总性能不错,是Linux系统首选的压缩工具,tar归档命令的-z参数也是利用gzip/gunzip来解压缩 [语法格式] Gip[选项][ ...

随机推荐

  1. SharePoint 2013 APP 开发示例 (三)使用远程的web资源

    在这个示例里我们将详细介绍 TokenHelper 类, 我们将看到它是怎么简单地从远程web站点访问SharePoint的.我们还将取到它的一些值.这将帮助我们理解连接是怎么被构造的,同时也方便我们 ...

  2. luogu2149 Elaxia的路线 (dijkstra+拓扑dp)

    先标记上一个人所有最短路上的边(同时也要标记反向边) 然后拿着另一个人最短路上的边(会构成一个DAG)去做拓扑dp,记从原点到某个点的最大的某个路径的被标记的边的个数 #include<bits ...

  3. Windows 10中设置自动登录

    步骤 使用WinKey+R打开运行,输入netplwiz. 在打开的用户账户对话框-用户选项卡-取消勾选要使用本计算机,用户必须输入用户名和密码(E). 点击应用按钮,在弹出的自动登录对话框中输入相关 ...

  4. 猜数字小游戏,很naive......

    这里用到了随机数生成器以及ctime #include <cstdio> #include <cstdlib> #include <ctime> #include ...

  5. Gradle安装 Gradle效率提升 eclipse安装gradle插件 【我】

    Gradle安装 从官网下载 gradle4.6版本,也可以从svn地址下载 https://downloads.gradle.org/distributions/gradle-4.6-bin.zip ...

  6. python备份网站,并删除指定日期文件

    #!/usr/bin/python# Filename: backup_ver1.pyimport osimport timeimport datetime# 1. The files and dir ...

  7. SQL Server 关于CROSS APPLY 和 OUTER APPLY应用

    先看看语法: <left_table_expression>  {cross|outer} apply<right_table_expression> 再让我们了解一下appl ...

  8. Python常用内置模块之xml模块

    xml即可扩展标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言.从结构上,很像HTML超文本标记语言.但他们被设计的目的是不同的,超文本标记语言被设计用来显示 ...

  9. loadrunner之WebServices协议脚本编写(三种请求模式)

    以天气预报网站为例:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl 一.web_service_call模式 步骤如下 ...

  10. Hadoop生态圈-使用Ganglia监控flume中间件

    Hadoop生态圈-使用Ganglia监控flume中间件 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Ganglia监控简介 加州伯克利大学千禧计划的其中一个开源项目.是一 ...