Repository navigation
Conversation
…on and checksum streams - IFile.Writer writes each record as several small writes (key and value lengths, key, value) straight into the codec stream (Snappy: a synchronized Compressor.setInput per call) or the checksum stream - An unsynchronized 64 KB write buffer behind NonSyncDataOutputStream batches them; close() drains it before finishing the codec and checksum streams; a Writer is confined to one thread - Microbenchmark (median of 6, JDK 21): IFile.Writer per record -12.5 % (Snappy) and -67.6 % (no codec); small rows -33 % / -72 %; UnorderedPartitionedKVWriter end to end -5.8 % to -12.6 % (24 and 1,009 partitions) - Hive on Tez, TPC-DS 10 TB: the shuffle write path (ReduceSink serialization + UnorderedPartitionedKVWriter + IFile + Snappy) is 46-72 % of task CPU in the shuffle-heavy queries
abstractdog
requested changes
Oct 22, 2026
abstractdog
left a comment
Contributor
There was a problem hiding this comment.
looks good, minor comments only
| @InterfaceStability.Unstable | ||
| @SuppressWarnings({"unchecked", "rawtypes"}) | ||
| public static class Writer { | ||
| private static final int WRITE_BUFFER_SIZE = 64 * 1024; |
Contributor
There was a problem hiding this comment.
possible follow-up: use initial size of 4 * 1024 and grow until 64 * 1024
Member
Author
There was a problem hiding this comment.
- BufferedOutputStream (thread-safe) +5–6 % (Snappy) / +13–47 % (no codec);
- 4 KB costing +150 % on the no-codec path, which is Tez's default configuration.
We could do more measurements in the follow-up
| } | ||
|
|
||
| /** {@link java.io.BufferedOutputStream} without its per-call lock. */ | ||
| private static final class WriteBuffer extends FilterOutputStream { |
Contributor
There was a problem hiding this comment.
maybe add unit tests the exercise 3 different paths:
- single 64KB write
- single
> 64KBwrite - 63 KB + 2 KB writes
Member
Author
There was a problem hiding this comment.
added + extracted writer to a separate class - NonSyncBufferedOutputStream
…o and cover it with tests
- NonSyncBufferedOutputStream in tez-common, beside NonSyncDataOutputStream and the two
NonSyncByteArray streams; IFile uses it instead of a private copy
- tests for the three buffer paths plus the single-byte boundary, close() and a rejected size:
they assert the downstream write sizes, so a regression in the large-write bypass is caught
- java.io.BufferedOutputStream measured as the alternative: +5-6% CPU/record with Snappy and
+13-47% without a codec (1M records, median of 9 after 3 warmups, JDK 21), so the
unsynchronized copy stays
|
💔 -1 overall
This message was automatically generated. |
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.
IFile.Writerwrites every record as several small writes (the key and value lengths as vints, then the key and valuebytes) directly into the codec stream, or into the checksum stream when there is no codec. Each call is a full trip
into the stream: with Snappy, a synchronized
Compressor.setInputand friends per call; without a codec, the checksumupdate per call.
The patch puts an unsynchronized 64 KB write buffer behind a
NonSyncDataOutputStreambetween the writer and thosestreams, so the per-record writes land in one array and reach the codec in large chunks.
close()drains the bufferbefore it finishes the codec and checksum streams. A Writer is confined to one thread, so the buffer takes no lock
(
BufferedOutputStreamlocks on every call).Microbenchmark (JDK 21, 6 runs each, median CPU per record; base = master):
Context: in Hive on Tez (LLAP), TPC-DS 10 TB, the shuffle write path (ReduceSink serialization, then
UnorderedPartitionedKVWriter, IFile and Snappy) is 46-72 % of task CPU in the shuffle-heavy queries.
Tests: tez-runtime-library TestIFile, TestUnorderedPartitionedKVWriter, TestPipelinedSorter, TestDefaultSorter,
TestMergeManager, TestTezMerger: 455 run, 0 failures. Removing the drain in
close()fails 179 of them, so the existinground-trip tests cover the new path.