Live data from Hacker News

pigz: A parallel implementation of gzip for multi-core machines

github.com

41–50 of 107 posts

Re: pigz: A parallel implementation of gzip for multi-core machines

#41
post #35
post #17

Earlier quoted context omitted.

bzip2 is very very slow though. Some types of data compress quite well with bzip, but if high compression is needed, xz is usually as good or better and natively has multithreading available. For everything else, there's zstd (also natively multithread)

Interesting https://docs.rs/zstd/latest/zstd/stream/write/struct.Encoder...

Decompression is multithreaded by default. Compression with an argument. However it is built-in.

Re: pigz: A parallel implementation of gzip for multi-core machines

#42
I use this all the time. It's a big time saver on multi-core machines (which is pretty much every desktop made in the past 20 years). It's available in all the repos, but not included by default (at least in Ubuntu/Mint). It is most useful for compressing disk images on-the-fly while backing them up to network storage. It's usually a good idea to zero unused space first:

(unprivileged commands follow)

dd if=/dev/zero of=~/zeros bs=1M; sync; rm ~/zeros

Compressing on the fly can be slower than your network bandwidth depending on your network speed, your processor(s) speed, and the compression level, so you typically tune the compression level (because the other two variables are not so easy to change). Example backup:

(privileged commands follow)

pv (Note that on slower systems the ssh encryption can also slow things down.)

Some sharp people may notice that it's not necessarily a good idea to back up a live system this way because the filesystem is changing while the system runs. It's usually just fine on an unloaded system that uses a journaling filesystem.

Re: pigz: A parallel implementation of gzip for multi-core machines

#43
post #36

Earlier quoted context omitted.

What is xzip? are you talking about xz?

yes, xz section 3.6 here https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Mar... https://en.wikipedia.org/wiki/XZ_Utils

The author of lzip has pointed criticism for the design choices of xz.

I generally use lzip for data that is important to me.

https://www.nongnu.org/lzip/xz_inadequate.html

Re: pigz: A parallel implementation of gzip for multi-core machines

#44

Earlier quoted context omitted.

pigz has the advantage of producing output that can be read by standard gzip processing tools (including, of course, gzip/gunzip), which are available by default on just about every OS out there so you get the faster archive creation speed without adding requirements to those who might be accessing the results later. It works because gzip streams can be tracked together as a single stream, at the start of each block…

yes, one consideration is whether you're creating archives for your own later use, or internal use where you also have zstandard and xz handling tools. Or to send somewhere else for wider use on unknown platforms.

Aye, pick the right tool for the target audience. If you are the target or you know everyone else who needs to read the output will have the ability to read zstd, go with that. If not consider pigz. If writing a script that others may run, have it default to gzip but use pigz if available (unless you really don't want that small % drop on compression).

Re: pigz: A parallel implementation of gzip for multi-core machines

#45
post #30

One interesting trivia is that since ~2020 Docker will transparently use pigz for decompressing container image layers if it's available on the host. This was a nice speedup for us, since we use large container images and automatic scaling for incoming traffic surges.

I think dracut also uses pigz to create the initrd when installing a new Linux kernel rpm package.

Re: pigz: A parallel implementation of gzip for multi-core machines

#46
post #38

The bit I found most interesting was actually: https://github.com/madler/pigz/blob/master/try.h https://github.com/madler/pigz/blob/master/try.c which implements try/catch for C99.

But why? Most modern languages try to get rid of exceptions (Go, Kotlin, Rust).

Golang has panic / recover / defer which are functionally similar to exceptions. It's actually a fun exercise to implement a pseudo-syntax for try/catch/finally in terms of those primitives.

Re: pigz: A parallel implementation of gzip for multi-core machines

#48
post #32

Earlier quoted context omitted.

I also thought the name was clever, but your comment made it even more interesting. Also, my first thought was, "is this safe to use?", I heard of gzip vulnerabilities before, but a parallel implementation sounds a lot easier to get wrong.

Gzip streams support dictionary resets which means you can concatenate individually commuters blocks together to make a while stream. This is what pigz is doing: shooting the input into blocks, spreading the compression of these blocks over different threads so multiple cores can be used, then joining the results together in the right order. It is the very same property of the format that gzip's own --rsyncable optio…

Given that, why wouldn't this just be upstreamed into gzip? If it's a clean, simple solution that's just expanding the use of a technique that's already in the core binary?

Re: pigz: A parallel implementation of gzip for multi-core machines

#49

I use this all the time. It's a big time saver on multi-core machines (which is pretty much every desktop made in the past 20 years). It's available in all the repos, but not included by default (at least in Ubuntu/Mint). It is most useful for compressing disk images on-the-fly while backing them up to network storage. It's usually a good idea to zero unused space first: (unprivileged commands follow) dd if=/dev/zero…

Alternative way of zeroing unused space without consuming all disk space: https://manpages.ubuntu.com/manpages/trusty/man8/zerofree.8....

Re: pigz: A parallel implementation of gzip for multi-core machines

#50

We used this to great effect at Facebook for MySQL backups in the early 2010s. The backup hosts had far more CPU than needed so it was a very nice speed-up over gzip. Eventually we switched to zstd, of course, but pigz never failed us.

Hey Eric! Hope you’re well!
Post reply on HN