Hash small items inline and bound the digest thread pool#2918
Open
T0k1To wants to merge 1 commit into
Open
Conversation
HashTask submits one task per algorithm per 1MB chunk to a shared unbounded thread pool and waits on a CountDownLatch, even when the item fits in a single chunk. For small items (the vast majority in a case) the executor round-trip and latch cost more than the hashing itself, and there is no next chunk to overlap with. Changes: - Items with size <= 1MB now update all digests inline in the worker thread, reusing a per-task buffer (also avoids allocating two 1MB buffers per small item). Multi-chunk items keep the previous pipelined path (read of the next chunk overlaps digesting of the current one, digests of a chunk run in parallel). - The shared pool is now bounded to the number of available processors. The unbounded cached pool could reach workers x algorithms threads (for example 24 workers x 4 algorithms = 96 digest threads competing with the 24 worker threads), oversubscribing the CPU. This matters most on low-core machines. Microbenchmark of the hashing stage (8 workers, MD5+SHA-1+SHA-256, CPU saturated, median of 3 runs): - 32KB items: 1.13x to 1.17x faster - 4KB items: 1.9x to 2.1x faster Both paths produce the same digests; behavior for large items is unchanged. Pure Java, no new dependencies.
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.
HashTask submits one task per algorithm per 1MB chunk to a shared unbounded thread pool and waits on a CountDownLatch, even when the item fits in a single chunk. For small items (the vast majority in a typical case) the executor round-trip and the latch cost more than the hashing itself, and there is no next chunk to overlap with.
Changes:
Microbenchmark of the hashing stage (8 workers, MD5+SHA-1+SHA-256, CPU saturated, 3 runs):
Both paths produce the same digests; behavior for large items is unchanged. Pure Java, no new dependencies, no OS- or hardware-specific code, and the change reduces (not increases) thread and memory pressure on low-end machines.