Package: rapidgzip
Rapidgzip: Parallelized Decompression of Gzip Files with Support for Fast Random AccessThis repository contains the command line toolrapidgzip, which can be used for parallel decompression of almost any gzip file. Other tools, such asbgzip, can only parallelize decompression of gzip files produced by themselves.rapidgzipworks with all files, especially those produced by the usually installedGNU gzip. How this works can be read in thepugz paperor in therapidgzip paper, which builds upon the former.The Python module provides aRapidgzipFileclass, which can be used to seek inside gzip files without having to decompress them first.
Alternatively, you can use this simply as aparallelizedgzip decoder as a replacement for Python's builtingzipmodule in order to fully utilize all your cores.The random seeking support is the same as provided byindexed_gzipbut further speedups are realized at the cost of higher memory usage thanks to a least-recently-used cache in combination with a parallelized prefetcher.Thisrepository is a light-weight fork of theindexed_bzip2repository, in which the main development takes place.
This repository was created for visibility reasons and in order to keep indexed_bzip2 and rapidgzip releases separate.
It will be updated at least for each release.
Issues regarding rapidgzip should be openedhere.Table of ContentsInstallationPerformanceScaling Benchmarks on 2xAMD EPYC CPU 7702 (2x64 cores)Scaling Benchmarks on Ryzen 3900XBenchmarks for Different CompressorsBenchmarks for Different DecompressorsUsageCommand Line ToolPython LibraryVia RatarmountC++ LibraryCitationAboutInternal ArchitectureTracing the DecoderInstallationYou can simply install it from PyPI:python3 -m pip install --upgrade pip  # Recommended for newer manylinux wheels
python3 -m pip install rapidgzip
rapidgzip --helpAdvanced InstallationsThe latest unreleased development version can be tested out with:python3-mpipinstall--force-reinstall'git+https://github.com/mxmlnkn/indexed_bzip2.git@master#egginfo=rapidgzip&subdirectory=python/rapidgzip'And to build locally, you can usebuildand install the wheel:cdpython/rapidgzip
rm-rfdist
python3-mbuild.
python3-mpipinstall--force-reinstall--userdist/*.whlPerformanceFollowing are benchmarks showing the decompression bandwidth over the number of used cores.There are two rapidgzip variants shown:(index)and(no index).
Rapidgzip is generally faster when given an index with--import-indexbecause it can delegate the decompression to ISA-l or zlib while it has to use its own custom-written gzip decompression engine when no index exists yet.
Furthermore, decompression can be parallelized more evenly and more effectively when an index exists because the serializing window propagation step is not necessary.The violin plots show 20 repeated measurements as a single "blob".
Thin blobs signal very reproducible timings while thick blobs signal a large variance.Scaling Benchmarks on 2xAMD EPYC CPU 7702 (2x64 cores)Decompression of Silesia CorpusThis benchmark uses theSilesia corpuscompressed as a .tar.gz file to show the decompression performance.
However, the compressed dataset is only ~69 MB, which is not sufficiently large to show parallelization over 128 cores.
That's why the TAR file is repeated as often as there are number of cores in the benchmark times 2 and then compressed into a single large gzip file, which is ~18 GB compressed and 54 GB uncompressed for 128 cores.Rapidgzip achieves up to 24 GB/s with an index and 12 GB/s without.Pugz is not shown as comparison because it is not able to decompress the Silesia dataset because it contains binary data, which it cannot handle.More BenchmarksDecompression of Gzip-Compressed Base64 DataThis benchmarks uses random data, that has been base64 encoded and then gzip-compressed.
This is the next best case for rapidgzip after the trivial case of purely random data, which cannot be compressed and therefore can be decompressed with a simple memory copy.
This next best case results in mostly Huffman-coding compressed data with only very few LZ77 back-references.
Without LZ77 back-references, parallel decompression can be done more independently and therefore faster than in the case of many LZ77 back-references.Decompression of Gzip-Compressed FASTQ DataThis benchmarks uses gzip-compressedFASTQ data.
That's why the TAR file is repeated as often as there are number of cores in the benchmark to hold the decompression times roughly constant in order to make the benchmark over this large a range feasible.
This is almost the worst case for rapidgzip because it contains many LZ77 back-references over very long ranges.
This means that a fallback to ISA-L is not possible and it means that the costly two-staged decoding has to be done for almost all the data.
This is also the reason why if fails to scale above 64 cores, i.e, to teh second CPU socket.
The first and second decompression stages are completely independently submitted to a thread pool, which on this NUMA architecture means, that data needs to be costly transferred from one processor socket to the other if the second step for a chunk is not done on the same processor as the first.
This should be fixable by making the ThreadPool NUMA-aware.These three scaling plots were created with rapidgzip 0.9.0 while the ones in thepaperwere created with 0.5.0.Scaling Benchmarks on Ryzen 3900XThese benchmarks on my local workstation with a Ryzen 3900X only has 12 cores (24 virtual cores) but the base frequency is much higher than the 2xAMD EPYC CPU 7702.Decompression With Existing Index4GiB-base644GiB-base6420x-silesia20x-silesiaUncompressed Size4 GiB3.95 GiBCompressed Size3.04 GiB1.27 GiBModuleBandwidth/ (MB/s)SpeedupBandwidth/ (MB/s)Speedupgzip25012931rapidgzip (0  threads)517920.6564018.8rapidgzip (1  threads)4881.96842.3rapidgzip (2  threads)9023.612004.0rapidgzip (6  threads)261710.4325010.9rapidgzip (12 threads)446317.7560018.7rapidgzip (24 threads)524020.8575019.2rapidgzip (32 threads)492919.6530017.7Decompression From Scratch4GiB-base644GiB-base6420x-silesia20x-silesiaUncompressed Size4 GiB3.95 GiBCompressed Size3.04 GiB1.27 GiBModuleBandwidth/ (MB/s)SpeedupBandwidth/ (MB/s)Speedupgzip25012931rapidgzip (0  threads)506020.120706.9rapidgzip (1  threads)4871.96302.1rapidgzip (2  threads)8393.36942.3rapidgzip (6  threads)23659.417405.8rapidgzip (12 threads)411616.419006.4rapidgzip (24 threads)497419.820406.8rapidgzip (32 threads)461218.325808.6Benchmarks for Different CompressorsThis benchmarks compresses the enlarged Silesia TAR with different gzip implementations, each with different compression levels.
Rapidgzip is then used to decompress the resulting files with 128 cores.Rapidgzip can parallelize decompression for almost all tested cases.
The only exception are files compressed withigzip -0, because these files conain only a single several gigabytes large deflate block.
This is the only known tool to produce such a pathological deflate block.The decompression bandwidth for the other compressors, varies quite a lot.
The fastest decompression is reached with 22 GB/s for bgzip-compressed files because the bgzip format is directly supported, which enabled rapidgzip to avoid the two-staged decompression method and also enables rapidgzip to offload all of the work to ISA-L.
Files compressed withbgzip -l 0decompress slightly slower with "only" 18 GB/s, because it creates a fully non-compressed gzip stream and therefore is more I/O bound than the other bgzip-generated files.Decompression of pigz-generated files is the slowest with 6 GB/s as opposed to 10-14 GB/s for gzip and igzip.
It is not clear why that is.
It might be becausepigzgenerates small deflate blocks and adds flush markers.The values in this chart are higher than in table 3 in thepaperbecause the measurements were done with rapidgzip 0.10.1 instead of version 0.5.0.Benchmarks for Different DecompressorsThis benchmarks uses different compressors and different decompressors to show multiple things:Single-core decompression of rapidgzip is close toigzipand roughly twice as fast asbgzip, which uses zlib.Decompression bandwidth with ISA-L can somewhat compete with zstd and is only 25% slower.Both,bgzipandpzstdcan only parallelize decompression of files compressed withbgzip/pzstd.
This especially means, that files compressed with the standardzstdtool cannot be decompressed in parallel and tops out at ~800 MB/s.Even for bgzip-compressed files, rapidgzip is always faster thanbgzipfor decompression, thanks to ISA-L and better multi-threading.Rapidgzip scales higher than pzstd for decompression with many cores, and can be more than twice as fast when an index exists: 24.3 GB/s vs. 9.5 GB/s.The values in this chart are higher than in table 4 in thepaperbecause the measurements were done with rapidgzip 0.10.1 instead ofversion 0.5.0.UsageCommand Line Toolrapidgzip--help# Parallel decoding: 1.7 stimerapidgzip-d-c-P0sample.gz|wc-c# Serial decoding: 22 stimegzip-d-csample.gz|wc-cPython LibrarySimple open, seek, read, and closefromrapidgzipimportRapidgzipFilefile=RapidgzipFile("example.gz",parallelization=os.cpu_count())# You can now use it like a normal filefile.seek(123)data=file.read(100)file.close()The first call to seek will ensure that the block offset list is complete and therefore might create them first.
Because of this the first call to seek might take a while.Use with context managerimportosimportrapidgzipwithrapidgzip.open("example.gz",parallelization=os.cpu_count())asfile:file.seek(123)data=file.read(100)Storing and loading the block offset mapThe creation of the list of gzip blocks can take a while because it has to decode the gzip file completely.
To avoid this setup when opening a gzip file, the block offset list can be exported and imported.Open a pure Python file-like object for indexed readingimportioimportosimportrapidgzipasrapidgzipwithopen("example.gz","rb")asfile:in_memory_file=io.BytesIO(file.read())withrapidgzip.open(in_memory_file,parallelization=os.cpu_count())asfile:file.seek(123)data=file.read(100)Via Ratarmountrapidgzipis the default backend in ratarmount since version 0.14.0.
Then, you can useratarmountto mount single gzip files easily.base64/dev/urandom|head-c$((4*1024*1024*1024))|gzip>sample.gz# Serial decoding: 23 stimegzip-c-dsample.gz|wc-c

python3-mpipinstall--userratarmount
ratarmountsample.gzmounted# Parallel decoding: 3.5 stimecatmounted/sample|wc-c# Random seeking to the middle of the file and reading 1 MiB: 0.287 stimeddif=mounted/samplebs=$((1024*1024))\iflag=skip_bytes,count_bytesskip=$((2*1024*1024*1024))count=$((1024*1024))|wc-cC++ libraryBecause it is written in C++, it can of course also be used as a C++ library.
In order to make heavy use of templates and to simplify compiling with Pythonsetuptools, it is mostly header-only so that integration it into another project should be easy.
The license is also permissive enough for most use cases.I currently did not yet test integrating it into other projects other than simply manually copying the source insrc/core,src/rapidgzip, and if integrated zlib is desired alsosrc/external/zlib.
If you have suggestions and wishes like support with CMake or Conan, please open an issue.CitationA paper describing the implementation details and showing the scaling behavior with up to 128 cores has been submitted to andacceptedinACM HPDC'23, The 32nd International Symposium on High-Performance Parallel and Distributed Computing.
The paper can also be accessedon ACM DLorArxiv.
The accompanying presentation can be foundhere.If you use this software for your scientific publication, please cite it as:@inproceedings{rapidgzip,author={Knespel, Maximilian and Brunst, Holger},title={Rapidgzip: Parallel Decompression and Seeking in Gzip Files Using Cache Prefetching},year={2023},isbn={9798400701559},publisher={Association for Computing Machinery},address={New York, NY, USA},url={https://doi.org/10.1145/3588195.3592992},doi={10.1145/3588195.3592992},abstract={Gzip is a file compression format, which is ubiquitously used. Although a multitude of gzip implementations exist, only pugz can fully utilize current multi-core processor architectures for decompression. Yet, pugz cannot decompress arbitrary gzip files. It requires the decompressed stream to only contain byte values 9–126. In this work, we present a generalization of the parallelization scheme used by pugz that can be reliably applied to arbitrary gzip-compressed data without compromising performance. We show that the requirements on the file contents posed by pugz can be dropped by implementing an architecture based on a cache and a parallelized prefetcher. This architecture can safely handle faulty decompression results, which can appear when threads start decompressing in the middle of a gzip file by using trial and error. Using 128 cores, our implementation reaches 8.7 GB/s decompression bandwidth for gzip-compressed base64-encoded data, a speedup of 55 over the single-threaded GNU gzip, and 5.6 GB/s for the Silesia corpus, a speedup of 33 over GNU gzip.},booktitle={Proceedings of the 32nd International Symposium on High-Performance Parallel and Distributed Computing},pages={295–307},numpages={13},keywords={gzip, decompression, parallel algorithm, performance, random access},location={Orlando, FL, USA},series={HPDC '23},}AboutThis tool originated as a backend forratarmount.
After writing the bzip2 backend forratarmount, my hesitation about reimplementing custom decoders for existing file formats has vastly diminished.
And, while random access to gzip files did exist withindexed_gzip, it did not support parallel decompression neither for the index creation nor when the index already exists.
The latter of which is trivial, when ignoring load balancing issues, but parallelizing even the index creation is vastly more complicated because decompressing data requires the previous 32 KiB of decompressed data to be known.After implementing a production-ready version by improving upon the algorithm used bypugz, I submitted apaper.
The review process was double-blind and I was unsure whether to pseudonymize Pragzip because it has already been uploaded to Github.
In the end, I used "rapidgzip" during the review process and because I was not sure, which form fields should be filled with the pseudonymized title, I simply stuck with it.
Rapidgzip was chosen for similar reason to pragzip, namely the P and RA are acronyms for Parallel and Random Access.
As rapgzip, did not stick, I used rapidgzip, which now also contains the foremost design goal in its name: being rapidly faster than single-threaded implementations.
Furthermore, the additional ID could be interpreted to stand for Index and Decompression, making "rapid" a partial backronym.Internal ArchitectureThe main part of theinternal architectureused for parallelizing is the same as used forindexed_bzip2.Tracing the DecoderPerformance profiling and tracing is done withScore-Pfor instrumentation andVampirfor visualization.
This is one way, you could install Score-P with most of the functionalities on Ubuntu 22.04.Installation of DependenciesInstallation steps for Score-Psudoapt-getinstalllibopenmpi-devopenmpi-bingcc-11-plugin-devllvm-devlibclang-devlibunwind-dev\libopen-trace-format-devotf-tracelibpapi-dev# Install Score-P (to /opt/scorep)SCOREP_VERSION=8.0
wget"https://perftools.pages.jsc.fz-juelich.de/cicd/scorep/tags/scorep-${SCOREP_VERSION}/scorep-${SCOREP_VERSION}.tar.gz"tar-xf"scorep-${SCOREP_VERSION}.tar.gz"cd"scorep-${SCOREP_VERSION}"./configure--with-mpi=openmpi--enable-shared--without-llvm--without-shmem--without-cubelib--prefix="/opt/scorep-${SCOREP_VERSION}"make-j$(nproc)makeinstall# Add /opt/scorep to your path variables on shell startcat<<EOF >> ~/.bashrcif test -d /opt/scorep; thenexport SCOREP_ROOT=/opt/scorepexport PATH=$SCOREP_ROOT/bin:$PATHexport LD_LIBRARY_PATH=$SCOREP_ROOT/lib:$LD_LIBRARY_PATHfiEOFecho-1|sudotee/proc/sys/kernel/perf_event_paranoid# Check whether it worksscorep--version
scorep-infoconfig-summaryTracingResults for a version from 2023-02-04Comparison without and with rpmalloc preloaded