abstractdog commented on PR #547:
URL: https://github.com/apache/tez/pull/547#issuecomment-7165051367

   > A spill of `UnorderedPartitionedKVWriter` opens an `IFile.Writer` per 
partition, and for Snappy and LZ4 each one goes through 
`codec.createOutputStream`: the codec parses its buffer size from the 
`Configuration` (under the codec's conf lock), and `BlockCompressorStream` 
allocates and zeroes a 256 KB buffer plus the compressed buffer, while a 
partition often holds a few KB. With 1,009 partitions that is ~336 MB allocated 
per spill. In Hive on Tez (LLAP), TPC-DS 10 TB, the part of this setup that the 
patch removes is 2.5 % (q75) and 2.8 % (q64) of LLAP CPU (profile in TEZ-4762).
   > 
   > The patch sizes each partition's stream to its data:
   > 
   > * `CodecUtils.getOutputBufferSize(codec)` reads the buffer size once per 
output (-1 for codecs other than Snappy and
   >   LZ4), and `CodecUtils.createOutputStream(codec, out, compressor, 
bufferSize, dataLength)` builds their
   >   `BlockCompressorStream` directly, with no `Configuration` lookup and no 
lock. A stream known to fit in one block gets a
   >   block of its length and a buffer of its compression bound, and writes 
the same bytes as the configured stream;
   >   otherwise the configured stream is used.
   > * `IFile.Writer` takes the codec buffer size and an upper bound of its raw 
length (`Writer.maxRawLength(records, keyValueBytes)`), and sizes its write 
buffer to the stream too.
   > * `UnorderedPartitionedKVWriter` passes each partition's bound from the 
buffers' record and byte counts on a spill, and
   >   the sum of the spilled raw lengths on the final merge. Other codecs and 
other writers keep `codec.createOutputStream`.
   > 
   > Microbenchmark (JMH, one spill of 1,009 partitions, 22 B records, JDK 21, 
Apple M-series, avgt of 10; before = the configured stream, as on master):
   > 
   > Codec      Per partition   Time    Allocated per spill
   > Snappy     22 B    -76 % (2,963 -> 703 us) 335.8 MB -> 5.2 MB
   > Snappy     2.2 KB  -48 % (4,878 -> 2,535 us)       335.8 MB -> 10.9 MB
   > Snappy     22 KB   -10 % (15,898 -> 14,310 us)     335.8 MB -> 62.1 MB
   > LZ4        22 B    -59 % (3,249 -> 1,346 us)       335.8 MB -> 5.2 MB
   > LZ4        2.2 KB  -41 % (5,153 -> 3,032 us)       335.8 MB -> 10.4 MB
   > LZ4        22 KB   -12 % (15,198 -> 13,431 us)     335.8 MB -> 57.8 MB
   > Tests: `TestCodecUtils` (a sized stream writes the same bytes as the 
configured one and round-trips, also when the length is underestimated), 
`TestIFile` (a sized writer writes the bytes of an unsized one), 
`TestUnorderedPartitionedKVWriter` (a spill's streams are sized to their 
partitions, bounded allocation, and every partition is written as the unsized 
path would); with the existing tests of the three classes, 401 run, 0 failures. 
Nine mutations of the sizing (no sizing, buffer without the compression bound, 
block one byte short, bound without the vints, spill unsized, spill reading the 
conf, merge ignoring the spills, write buffer unsized, spill bound from the 
first buffer) each fail at least one of them.
   
   please include a 220KB and maybe 1MB benchmark result, it would be fair to 
see that the patch is not supposed to introduce any regression


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to