brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: zstd -b1 -e19 benchmarks every compression level on your own file

Linux
~/tips/tip-archive-zstd-benchmark-levels

zstd -b1 -e19 app-backup.tar

Measures ratio and speed of each zstd level on your data, so you can pick one.

Every compression tool has levels, and most people pick one from a blog post and never think about it again. The right level depends on your data, though, and zstd will simply measure it for you.

Point the built-in benchmark at a file that looks like what you normally compress, say a tar of an appdata folder:

zstd -b1 -e19 app-backup.tar

-b1 starts at level 1 and -e19 ends at 19, the top of the normal range. For each level you get one line with the input size, the output size, the ratio, and the compression and decompression speed. Somewhere in that list the size stops shrinking much while the speed keeps dropping, and that is the level I would pick for that kind of data. The default is 3, which is often already close.

The benchmark uses one worker thread unless you say otherwise. If your real backups run with -T0, test with it too, or the speeds will not match:

zstd -b3 -e15 -T0 app-backup.tar

The caveat: zstd does the whole benchmark in memory, so a 20 GB tar needs that much free RAM. Take a representative piece of a few hundred megabytes instead. And the results only describe that kind of file. Text logs, databases and already compressed video behave completely differently, so a number from one says little about another.

Further reading: zstd(1) manual

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link