Skip to content

Multithreaded compression offers only a slight performance improvement #4762

Open

Description

@kakaacat

I used an 11.5 GB file to test the compression times under both single-threaded and multithreaded. Multithreading with ZSTD_c_nbWorkers, while single-threaded does not. The results show that single-threaded compression took 35.924 seconds, whilst multithreading took 33.879 seconds. Strangely, the efficiency gain from multithreading is minimal, could you explain why this is the case?

Activity

  1. sebres commented on Sep 9, 2026

    @sebres
    Contributor

    One possible explanation for the bottleneck could be the maximal speed of the disk drive.

    11.5GB / 36s is 320MB/s (looks like default compression level 3?), whereas 11.5GB / 34s is 340MB/s, what hypothetically could near to physical limit of read- and write-speed of your drive (SSD?), in case if the data is hardly compressible with that level.

    Can you repeat the test (single- and multi-threaded) with a bit increased level, e. g. 5-7?..
    I assume the difference would be more obvious.

    Or to exclude the factor physical limit of disk drive, simply compare the speed by redirecting compressed stream to /dev/null (or to NUL: on windows), for instance:

    zstd --single-thread -c /path/large-file > /dev/null
    zstd -T4 -c /path/large-file > /dev/null

    However there are still few details missing:

    • platform? (for example on windows you can additionally experience some AV-related latencies, as well as measurements may be confused by aggressive caching on side of FS)
    • which dataset was compressed (binary/text, good/bad compressible)?
    • level?
    • number of workers (used for ZSTD_c_nbWorkers)?
    • how many CPU threads free during compression?

    Anyway, here is the comparison how it may look compressing 4GB (raspbian image, cached read) on drive with IIRC ca. 2GB/s max write-speed, and as reference the same for /dev/null:

    SSD 2000MB/s/dev/null
    Wrk Lev Time Speed
    ST f60 4.793s 889MB/s
    T4 f60 3.524s 1209MB/s
    ST 1 11.587s 368MB/s
    T4 1 3.470s 1228MB/s
    ST 3 20.259s 210MB/s
    T4 3 7.515s 567MB/s
    ST 5 31.860s 134MB/s
    T4 5 14.056s 303MB/s
    Wrk Lev Time Speed
    ST f60 3.618s 1178MB/s
    T4 f60 1.998s 2132MB/s
    ST 1 10.495s 406MB/s
    T4 1 3.125s 1364MB/s
    ST 3 18.243s 234MB/s
    T4 3 6.751s 631MB/s
    ST 5 31.092s 137MB/s
    T4 5 13.125s 325MB/s

    As you can see multi-threaded is drastically faster than single-threaded, and only with fast-level 60 the difference is not quite as pronounced due to the proximity to the physical limits of my test system.

    @Cyan4973 & zstd/owners: would it not be better to enable discussions in the repo-settings, so questions like this may be asked there, instead of in issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions