Your bottlenecks are: how fast it can read the file, how fast it can compress it, and how fast it can write it or transfer it to the destination media, perhaps over the network.
First thing to do would be to run the gzip command while monitoring the output of
vmstat 1
in another terminal. You'll see if your CPU is maxed out, how many cores it uses, and how much MB/s it reads and writes. Also monitor vmstat while copying a huge file to get an idea of your hard drive's max read/write speed. Then you'll know if the operation is cpu bound or io bound.
You can also use
time gzip ...
It will tell you how much cpu time it used versus the total time, so that gives useful hints on whether it's cpu bound or waiting for IO.
If you intend to transfer the compressed file to another harddisk or over the network, then it makes sense to do so while compressing it, instead of using a separate copy operation. If the destination drive is local, just use the adequate gzip syntax ; if it is remote you can use a network share or:
gzip -c file.txt | ssh user@ip "cat > destfile.gz"
This will gzip the file and transfer it in one pipelined operation, which is faster than two separate steps.
Now, watch vmstat and determine if the operation is io-bound, network-bound, or cpu-bound. I recommend to install the utility "pv" and use it like this:
gzip -c file.txt | pv | ssh user@ip "cat > destfile.gz"
pv will display how many MB/s of compressed data is transferred through the network. You can test your HDD read, network, and write on the other end with this:
cat file.txt | pv | ssh user@ip "cat > destfile.gz"
You can test your HDD network and write on the other end with this:
cat /dev/zero | pv | ssh user@ip "cat > destfile.gz"
...and you can test only the network with this:
cat /dev/zero | pv | ssh user@ip "cat > /dev/null"
Now you should have a much better idea of what slows it down. Note if you use samba network shares you should also test the throughput:
cat /dev/zero | pv > /mnt/share/filename
...just in case your network share performance is clobbered by a misconfiguration, it's always nice to know.
If you determine that the problem is really gzip's speed, then the solution is to use a faster multithreaded compressor like zstandard. You can also use a faster compression setting, since saving a few GB of harddisk space is probably much less important than saving a few hours.
If compressed file size is less important than how long it takes, the optimum solution is a compression that is fast enough to saturate either the disk or network bottleneck.
For example if you have a slow network and a fast disk, and you have cpu to spare, using a higher compression setting will make it faster by transferring a smaller amount of compressed data. But if you have a fast network and a slow CPU, then a lower compression setting will use less CPU so it will be faster.
Now, where does this 100GB file comes from? This is not a common file size... and it hints that you should really be using rsync in delta mode.
pbzip2
) and parallel xz (xz --threads
) exist.xz --threads
means to use thexz
command with the--threads
parameter to paralellize the processing.zstdmt --adapt
aims to hit that sweet spot that saturates I/O and CPU, adapting on the fly (within a set range) to "perceived I/O conditions". man page. IDK if--adapt
is usable with--format=gzip
, to take advantage of that and zstd's threaded I/O (and compression) for the.gz
format.