当前位置:网站首页>tar之多线程解压缩
tar之多线程解压缩
2022-06-12 07:32:00 【早九晚十二】
大家好,我是早九晚十二,目前是做运维相关的工作。写博客是为了积累,希望大家一起进步!
我的主页:早九晚十二
关于tar
我们平常在服务器上操作时,经常会使用到tar命令,这是Unix和类Unix系统上的压缩打包工具,可以将多个文件合并为一个文件,打包后的文件后缀亦为“tar”。它可以在任何用户下使用。
同时,它有多个压缩率不同的版本,如tar.xz和tar.gz,前者的压缩率更高,但可能有兼容性问题。
如果大家使用过tar,一定都会有这个感受:当你在解压或者压缩一个超大文件时,速度会很慢!这是由于tar解压缩操作是用单线程去操作的,如果你在解压的时候,使用top命令,常常会看到某一个cpu飙升到100%。

今天我们就介绍一下,tar的多线程操作。
多线程安装
yum -y install pigz
pigz命令来自于英文词组”parallel implementation of gzip“的缩写,其功能是用于多线程的解压缩文件。与其他解压缩命令不同的是pigz命令支持多线程的并行处理方式,同比gzip能快60%以上,当然CPU的消耗也会更高。
#压缩文件
tar --use-compress-program=pigz -cvpf app.tar.gz app
#解压文件
tar --use-compress-program=pigz -xvpf app.tar.gz
--use-compress-program=pigz即代表使用的pigz工具,那么究竟效果如果呢,我们一起期待一下
结果测试
我们可以编写一个脚本,计算使用pigz和不使用的时间。
#!/bin/bash
echo "starttime: `date +"%Y-%m-%d %H:%M:%S"`" > tar.txt
sleep 5 #在这里填写我们的压缩命令
echo "endtime: `date +"%Y-%m-%d %H:%M:%S"`" >> tar.txt
start=`awk '{print $2,$3}' tar.txt | sed -n '1p'`
end=`awk '{print $2,$3}' tar.txt | sed -n '2p' `
echo $start
echo $end
starttime=$(date -d "$start" +%s) #转化为系统时间
endtime=$(date -d "$end" +%s)
runtime=$(($endtime-$starttime)) #计算程序运行时间
echo $runtime
单线程压缩
将sleep 5替换为tar -cvpf app.tar.gz app/后执行,输出结果为26s
多线程压缩
将sleep 5替换为tar --use-compress-program=pigz -cvpf app.tar.gz app后执行,输出结果为15s

根据以上测试结果,可以看到时间缩短了11s。解压的话,小伙伴们可以自己测试一下。
码字不易,希望大家有用到的可以三连支持一波。哪里有问题的话可以指出,谢谢大家!
边栏推荐
- Principle and application of PWM
- Right click the general solution of file rotation jam, refresh, white screen, flash back and desktop crash
- Unity uses shaders to highlight the edges of ugu I pictures
- R语言使用RStudio将可视化结果保存为pdf文件(export--Save as PDF)
- R语言将dataframe数据中指定数据列的数据从小数转化为百分比表示、数据转换为百分数
- Dynamic coordinate transformation in ROS (dynamic parameter adjustment + dynamic coordinate transformation)
- RT thread studio learning summary
- The first demand in my life - batch uploading of Excel data to the database
- 2022R2移动式压力容器充装试题模拟考试平台操作
- Vs2019 MFC IP address control control inherits cipaddressctrl class redrawing
猜你喜欢

Node, topic, parameter renaming and global, relative and private namespaces in ROS (example + code)

RT thread studio learning (IX) TF Card File System

Complete set of typescript Basics

Day 4 of pyhon

AI狂想|来这场大会,一起盘盘 AI 的新工具!

Golang 快速生成数据库表的 model 和 queryset

Day 5 of pyhon

Gd32f4 (5): gd32f450 clock is configured as 200m process analysis

GD32F4(5):GD32F450时钟配置为200M过程分析

RT thread studio learning (VIII) connecting Alibaba cloud IOT with esp8266
随机推荐
8086/8088 instruction execution pipeline disconnection reason
2022 G3 boiler water treatment recurrent training question bank and answers
Complete set of typescript Basics
Summary of machine learning + pattern recognition learning (I) -- k-nearest neighbor method
Voice assistant - Multi round conversation (theory and concept)
2022电工(初级)考试题库及模拟考试
Keil installation of C language development tool for 51 single chip microcomputer
Detailed explanation of coordinate tracking of TF2 operation in ROS (example + code)
AI fanaticism | come to this conference and work together on the new tools of AI!
Use of gt911 capacitive touch screen
Source code learning - [FreeRTOS] privileged_ Understanding of function meaning
Improved schemes for episodic memory based lifelong learning
Esp8266 firmware upgrade method (esp8266-01s module)
Static coordinate transformation in ROS (analysis + example)
RT thread studio learning summary
Interview computer network - transport layer
Golang quickly generates model and queryset of database tables
Voice assistant - overall architecture and design
私有协议的解密游戏:从秘文到明文
Learning to continuously learn paper notes + code interpretation




