← Blog
An ivory strip of paper folded into an accordion, held by a mint-green band on a lavender background.
Published on
2026-12-01

Zstd vs gzip for archived application logs

Start with the machine that will have to read your archived logs during an incident. If its recovery tools only open gzip, keep writing .gz files. If you control both ends, test Zstandard (Zstd) on a closed log file. In our benchmark, Zstd wrote and restored both raw logs faster, but the smallest archive depended on what the application logged.

For 300,000 JSON request records, gzip saved about 170 KB per file compared with Zstd. For a repetitive worker log, Zstd saved about half a megabyte and finished writing in 29 milliseconds. Those two workloads suggest different choices for a service that rotates logs every few minutes.

Zstd vs gzip on three log files

We compared gzip level 6 with Zstd level 3. These are settings you can put into a rotation job and measure on your own hardware. The level numbers belong to different compression algorithms. Each time below is the median of five runs, rounded to the nearest millisecond. Archive sizes are in bytes.

JSON requests with unique IDs

The input held 49,458,502 bytes. Field names and routes repeated, but each request had a generated 128-bit ID. Gzip produced 9,087,912 bytes in 717 ms and restored the file in 131 ms. Zstd produced 9,257,502 bytes in 183 ms and restored it in 74 ms.

Gzip’s compression ratio was 5.44 to 1, compared with 5.34 to 1 for Zstd. If the writer has to finish before the next rotation, Zstd bought about 534 ms per file here. If you retain many copies of this particular log for months, gzip’s 169,590-byte advantage may matter more. Multiply the measured gap by the number of files you actually keep.

Worker logs with repeated messages

The second input held 240,000 job completions in 25,141,617 bytes. Timestamps, worker IDs and item counts changed. Most of each log message stayed the same. Gzip wrote 1,129,196 bytes in 164 ms and restored them in 43 ms. Zstd wrote 615,037 bytes in 29 ms and restored them in 29 ms. Here Zstd saved 45.5% of the gzip archive size as well as writer time.

A log that was already compressed

We fed the 9,087,912-byte gzip request archive back through each writer. Gzip added 2,778 bytes and Zstd added 220. Unpacking either outer archive returned the original .gz file. A second decode was still needed to read a log line. If your collector already receives compressed logs, check the incoming format before adding a compression stage.

How much compression is worth the CPU time?

Gzip compression uses the DEFLATE algorithm, which represents repeated byte sequences with references and uses Huffman coding to encode symbols. Repetitive patterns help explain why both tools packed the worker log so tightly. The compression ratio was about 22 to 1 for gzip and 41 to 1 for Zstd. The JSON sample carried a new random ID in every record and reached roughly 5 to 1 with either format. A single assumed ratio would give a poor estimate of storage costs for at least one of these services.

If size or compression speed misses your target, change one setting per run. Try another compression level on the same file before enabling multiple Zstd compression threads. Extra threads can shorten elapsed time while competing with the application for CPU and memory. For a collection of small, similar files, a trained Zstd dictionary is another option. When you use one, keep the matching dictionary available to the recovery client for the full retention period. See the Zstd compressor settings.

What the timings include

We ran the comparison locally on an AMD Ryzen 7 7840HS under Windows 11, using Python 3.12.14, zlib 1.3.2 and python-zstandard 0.25.0 with libzstd 1.5.7. Both writers ran single-threaded and streamed 1 MiB chunks to a local file. The Zstd writer enabled a frame checksum and used no dictionary. The gzip writer omitted the source name and fixed the header timestamp.

We ran one warm-up, alternated the order of the codecs, then measured five writes and five restores per format and input. Elapsed time included buffered file reads, compression or decompression, and writes. The operating system could cache data. Network transfer, a forced flush to physical disk and the final SHA-256 check were outside the timing. The inputs were synthetic.

Process CPU time helps size the archive worker. For the JSON input, median CPU time to write and restore was 719 and 109 ms for gzip, and 188 and 63 ms for Zstd. For the worker log, the same figures were 156 and 31 ms for gzip, and 31 and 31 ms for Zstd. The Windows process clock reported in roughly 16 ms increments on this machine, so small differences in CPU time tell you little. The Zstandard project’s benchmarks document their own inputs and settings if you want a second point of comparison.

Check the decoder on the recovery machine

Save the SHA-256 digest of the original closed log in a trusted manifest. Copy a sample archive and its expected digest to the machine or container the on-call team will use. Run the check with the tools already there. Python includes a gzip reader. For the .zst branch of this example, we installed zstandard==0.25.0 in the writer’s Python environment. Check whether the recovery environment already has that module before relying on it.

Save this as verify_log.py and run python verify_log.py archive.gz EXPECTED_SHA256, substituting the actual filename and digest. It reads the decompressed bytes in chunks and exits with an error if the digest differs. The check works without writing a second copy of a large log.

import gzip
import hashlib
import sys
from pathlib import Path

archive = Path(sys.argv[1])
expected = sys.argv[2].lower()
with archive.open("rb") as raw:
    if archive.suffix == ".gz":
        stream = gzip.GzipFile(fileobj=raw)
    elif archive.suffix == ".zst":
        import zstandard
        stream = zstandard.ZstdDecompressor().stream_reader(raw)
    else:
        raise SystemExit("Expected .gz or .zst")
    with stream:
        digest = hashlib.sha256()
        for chunk in iter(lambda: stream.read(1024 * 1024), b""):
            digest.update(chunk)

if digest.hexdigest() != expected:
    raise SystemExit("SHA-256 mismatch")
print("SHA-256 OK")

For an independent check, we put just the six archives and a digest manifest in a clean directory and decoded them with Node.js 24’s built-in decoders on the same physical machine. All six restored inputs matched. That verifier also rejected copies missing their last 16 bytes, one for each format. Before changing production, repeat the drill in your actual recovery image, including an attempt with a damaged copy.

Choose the archive format for your rotation job

  • Choose gzip when an existing consumer requires it, when the rescue image already supports it, or when your own retention sample gives it a worthwhile size advantage.
  • Choose Zstd when the writer is falling behind, repeated log data compresses well, and every recovery tool can decode your chosen settings. Measure the slowest consumer before changing the whole fleet.
  • Keep incoming archives as they are when a second compression pass saves no space. If you need to retrieve an hour of logs quickly, rotate into appropriately sized files and record their time ranges. Neither of the single compressed streams in this test provided an index of log lines.

Start with a typical rotation and one from a busy or noisy hour. If you control the application, our Python logging guide can help you decide which fields belong in those files. If the destination stores columns for analytics, test that format separately with the Parquet compression guide.

For a job you plan to run on a CPU instance with Hivenet, repeat the comparison on the instance size you intend to use. Record archive bytes, CPU time and elapsed restore time while the application is under its usual load. Then time a download and a restore from your storage destination. That last number is the one your on-call team has to live with.

Your next workload belongs on Hivenet.

Pick one AI, compute, or storage workload and see the difference for yourself. Spin it up in minutes, or let our team map your fastest path to production.