Repository navigation
zstdmt: give the thread pools a queue so small jobs run in parallel - #4921
Open
JonSnow1807 wants to merge 1 commit into
Open
JonSnow1807 wants to merge 1 commit into
JonSnow1807 wants to merge 1 commit into
Conversation
…llel The internal pool of a ZSTDMT_CCtx, and the pool created by ZSTD_createThreadPool(), had no queue. POOL_tryAdd() then fails until a worker has woken up and taken the previous job. When the next job is prepared faster than that, it is kept as jobReady, the next call makes no input progress, and ZSTDMT_flushProduced() waits until the oldest job has finished. With small jobs (ZSTDMT_JOBSIZE_MIN lowered at compile time), nearly every job then waits for the previous one. The queue size was reduced to 0 in 2017 to save memory, when a job waiting in the queue held its own input buffer. Since commit d932fb6 (2018), the input of every job is in the round buffer, which is allocated in advance and reused, and a worker gets its output buffer when it starts the job, so a queued job holds no buffer. The number of jobs in flight is still bounded by the jobs table and by the round buffer. - the internal pool gets a queue of nbWorkers jobs. POOL_resize() keeps the queue size, so when a context is reused with more workers, its internal pool is replaced instead (all its jobs have completed by then). - ZSTD_createThreadPool(numThreads) gets a queue of numThreads jobs. - zstreamtest: new test checking that a job is accepted while the only worker is busy (fails without this change). The abandoned frame test now posts a third job, so that a prepared job that is not yet posted is still covered. The compressed output is unchanged. Issue meta#4890
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Addresses the first part of #4890. ZSTDMT creates its thread pool with a queue of 0, and so does
ZSTD_createThreadPool(). Without a queue,POOL_tryAdd()fails until a worker has taken the previous job, and the prepared job then waits for the oldest job to finish, so small jobs can run one after another. The queue was set to 0 in 2017 (7db5526, “reduced pool queue to 0 to save memory”), when a queued job held its own input buffer. Since #1045 the inputs live in the round buffer, so a queued job holds no buffer.This gives the internal pool a queue of
nbWorkersandZSTD_createThreadPool(n)a queue ofn. It also replaces the internal pool when a context is reused with more workers, sincePOOL_resize()can’t grow the queue. Pools provided by the application are untouched. Compressed output is byte-identical (all Silesia files, 13 parameter sets including LDM, rsyncable and a shared pool).Performance, on 2 MiB of dickens (median of 5 processes, -O3):
ZSTDMT_JOBSIZE_MINset to 128 KiB, level -4, 16 workers: 480 to 2928 MiB/s on an Apple M2 Pro (Apple clang 17), and geomean 1.10× (at most 1.36×) on a Ryzen 9 5950X (gcc 13, pinned), where workers wake up in time more often.A new zstreamtest test checks that a job is accepted while the only worker is busy. It fails on dev and passes with the change.
Checklist
Tools used
Code drafted by both human and AI, and reviewed by human.