You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2024/12/18 20:15:06 UTC
[PR] [do not review] experimental support for lz4 compression (not working) [datafusion-comet]
andygrove opened a new pull request, #1181:
URL: https://github.com/apache/datafusion-comet/pull/1181
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## How are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: Add support for LZ4 compression [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #1181:
URL: https://github.com/apache/datafusion-comet/pull/1181#issuecomment-2560034413
LZ4 support is now part of https://github.com/apache/datafusion-comet/pull/1192
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] [do not review] experimental support for lz4 compression (not working) [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #1181:
URL: https://github.com/apache/datafusion-comet/pull/1181#discussion_r1890829417
##########
native/core/src/execution/shuffle/shuffle_writer.rs:
##########
@@ -1543,14 +1569,38 @@ pub(crate) fn write_ipc_compressed<W: Write + Seek>(
// write ipc_length placeholder
output.write_all(&[0u8; 8])?;
- // write ipc data
- // TODO: make compression level configurable
- let mut arrow_writer = StreamWriter::try_new(zstd::Encoder::new(output, 1)?, &batch.schema())?;
- arrow_writer.write(batch)?;
- arrow_writer.finish()?;
+ let output = match codec {
+ CompressionCodec::Lz4 => {
+ // write IPC first without compression
+ let mut buffer = vec![];
+ let mut arrow_writer = StreamWriter::try_new(&mut buffer, &batch.schema())?;
+ arrow_writer.write(batch)?;
+ arrow_writer.finish()?;
+ let ipc_encoded = arrow_writer.into_inner()?;
+
+ let mut encoder = lz4::EncoderBuilder::new()
+ .content_size(ipc_encoded.len() as u64)
+ .checksum(ContentChecksum::ChecksumEnabled)
+ .block_checksum(BlockChecksum::BlockChecksumEnabled)
+ .level(4)
+ .block_size(BlockSize::Default)
+ .auto_flush(true)
+ .build(&mut *output)?;
+ encoder.write_all(ipc_encoded.as_slice())?;
+ let (output, result) = encoder.finish();
+ result?;
+ output
+ }
+ CompressionCodec::Zstd(level) => {
+ let encoder = zstd::Encoder::new(output, *level)?;
+ let mut arrow_writer = StreamWriter::try_new(encoder, &batch.schema())?;
Review Comment:
Yes, that is something I have been thinking about as well. We have the cost of writing the schema for each batch currently, and the schema is guaranteed to be the same for each batch.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] [do not review] experimental support for lz4 compression (not working) [datafusion-comet]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #1181:
URL: https://github.com/apache/datafusion-comet/pull/1181#discussion_r1890821939
##########
native/core/src/execution/shuffle/shuffle_writer.rs:
##########
@@ -1543,14 +1569,38 @@ pub(crate) fn write_ipc_compressed<W: Write + Seek>(
// write ipc_length placeholder
output.write_all(&[0u8; 8])?;
- // write ipc data
- // TODO: make compression level configurable
- let mut arrow_writer = StreamWriter::try_new(zstd::Encoder::new(output, 1)?, &batch.schema())?;
- arrow_writer.write(batch)?;
- arrow_writer.finish()?;
+ let output = match codec {
+ CompressionCodec::Lz4 => {
+ // write IPC first without compression
+ let mut buffer = vec![];
+ let mut arrow_writer = StreamWriter::try_new(&mut buffer, &batch.schema())?;
+ arrow_writer.write(batch)?;
+ arrow_writer.finish()?;
+ let ipc_encoded = arrow_writer.into_inner()?;
+
+ let mut encoder = lz4::EncoderBuilder::new()
+ .content_size(ipc_encoded.len() as u64)
+ .checksum(ContentChecksum::ChecksumEnabled)
+ .block_checksum(BlockChecksum::BlockChecksumEnabled)
+ .level(4)
+ .block_size(BlockSize::Default)
+ .auto_flush(true)
+ .build(&mut *output)?;
+ encoder.write_all(ipc_encoded.as_slice())?;
+ let (output, result) = encoder.finish();
+ result?;
+ output
+ }
+ CompressionCodec::Zstd(level) => {
+ let encoder = zstd::Encoder::new(output, *level)?;
+ let mut arrow_writer = StreamWriter::try_new(encoder, &batch.schema())?;
Review Comment:
I am not really familiar with the code, but shouldn't `StreamWriter` and encoder be created only once per stream instead of per batch?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] [do not review] experimental support for lz4 compression (not working) [datafusion-comet]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #1181:
URL: https://github.com/apache/datafusion-comet/pull/1181#discussion_r1892442856
##########
native/core/src/execution/shuffle/shuffle_writer.rs:
##########
@@ -1543,14 +1569,38 @@ pub(crate) fn write_ipc_compressed<W: Write + Seek>(
// write ipc_length placeholder
output.write_all(&[0u8; 8])?;
- // write ipc data
- // TODO: make compression level configurable
- let mut arrow_writer = StreamWriter::try_new(zstd::Encoder::new(output, 1)?, &batch.schema())?;
- arrow_writer.write(batch)?;
- arrow_writer.finish()?;
+ let output = match codec {
+ CompressionCodec::Lz4 => {
+ // write IPC first without compression
+ let mut buffer = vec![];
+ let mut arrow_writer = StreamWriter::try_new(&mut buffer, &batch.schema())?;
+ arrow_writer.write(batch)?;
+ arrow_writer.finish()?;
+ let ipc_encoded = arrow_writer.into_inner()?;
+
+ let mut encoder = lz4::EncoderBuilder::new()
+ .content_size(ipc_encoded.len() as u64)
+ .checksum(ContentChecksum::ChecksumEnabled)
+ .block_checksum(BlockChecksum::BlockChecksumEnabled)
+ .level(4)
+ .block_size(BlockSize::Default)
+ .auto_flush(true)
+ .build(&mut *output)?;
+ encoder.write_all(ipc_encoded.as_slice())?;
+ let (output, result) = encoder.finish();
+ result?;
+ output
+ }
+ CompressionCodec::Zstd(level) => {
+ let encoder = zstd::Encoder::new(output, *level)?;
+ let mut arrow_writer = StreamWriter::try_new(encoder, &batch.schema())?;
Review Comment:
Besides writing the schema each time, I guess it will also have higher overhead of flushing each time (less efficient buffering), having lower compressibility, etc. ?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] [do not review] experimental support for lz4 compression (not working) [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #1181:
URL: https://github.com/apache/datafusion-comet/pull/1181#issuecomment-2552512228
Here are my findings from hacking on this today.
LZ4 provides two compression formats: `LZ4 Block Format` and `LZ4 Frame Format`.
Spark uses the Java library https://github.com/lz4/lz4-java and specifically uses `LZ4BlockOutputStream` which seems to be a proprietary streaming LZ4 format, as noted in the documentation:
```
/**
* Streaming LZ4 (not compatible with the LZ4 Frame format).
* This class compresses data into fixed-size blocks of compressed data.
* This class uses its own format and is not compatible with the LZ4 Frame format.
* For interoperability with other LZ4 tools, use {@link LZ4FrameOutputStream},
* which is compatible with the LZ4 Frame format. This class remains for backward compatibility.
* @see LZ4BlockInputStream
* @see LZ4FrameOutputStream
*/
public class LZ4BlockOutputStream extends FilterOutputStream {
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: Add support for LZ4 compression [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #1181:
URL: https://github.com/apache/datafusion-comet/pull/1181#issuecomment-2557670571
Current status:
:heavy_check_mark: I can run real benchmarks
:heavy_check_mark: shuffle write encoding + compression time is improved
:face_with_head_bandage: Overall query time is more than 10x slower, so perhaps there is an issue with the reader side now

--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: Add support for LZ4 compression [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #1181:
URL: https://github.com/apache/datafusion-comet/pull/1181#issuecomment-2557664830
The lz4_flex crate should get even faster once https://github.com/PSeitz/lz4_flex/pull/175 is merged
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: Add support for LZ4 compression [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove closed pull request #1181: feat: Add support for LZ4 compression
URL: https://github.com/apache/datafusion-comet/pull/1181
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] [do not review] experimental support for lz4 compression (not working) [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #1181:
URL: https://github.com/apache/datafusion-comet/pull/1181#issuecomment-2557609589
switched to lz4_flex crate:
```
shuffle_writer/shuffle_writer: encode and compress (zstd)
time: [209.27 µs 211.21 µs 213.47 µs]
shuffle_writer/shuffle_writer: encode and compress (lz4 frame)
time: [162.58 µs 165.17 µs 167.76 µs]
shuffle_writer/shuffle_writer: encode and compress (lz4 block)
time: [180.16 µs 183.93 µs 188.09 µs]
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] [do not review] experimental support for lz4 compression (not working) [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #1181:
URL: https://github.com/apache/datafusion-comet/pull/1181#discussion_r1892843414
##########
native/core/src/execution/shuffle/shuffle_writer.rs:
##########
@@ -1543,14 +1569,38 @@ pub(crate) fn write_ipc_compressed<W: Write + Seek>(
// write ipc_length placeholder
output.write_all(&[0u8; 8])?;
- // write ipc data
- // TODO: make compression level configurable
- let mut arrow_writer = StreamWriter::try_new(zstd::Encoder::new(output, 1)?, &batch.schema())?;
- arrow_writer.write(batch)?;
- arrow_writer.finish()?;
+ let output = match codec {
+ CompressionCodec::Lz4 => {
+ // write IPC first without compression
+ let mut buffer = vec![];
+ let mut arrow_writer = StreamWriter::try_new(&mut buffer, &batch.schema())?;
+ arrow_writer.write(batch)?;
+ arrow_writer.finish()?;
+ let ipc_encoded = arrow_writer.into_inner()?;
+
+ let mut encoder = lz4::EncoderBuilder::new()
+ .content_size(ipc_encoded.len() as u64)
+ .checksum(ContentChecksum::ChecksumEnabled)
+ .block_checksum(BlockChecksum::BlockChecksumEnabled)
+ .level(4)
+ .block_size(BlockSize::Default)
+ .auto_flush(true)
+ .build(&mut *output)?;
+ encoder.write_all(ipc_encoded.as_slice())?;
+ let (output, result) = encoder.finish();
+ result?;
+ output
+ }
+ CompressionCodec::Zstd(level) => {
+ let encoder = zstd::Encoder::new(output, *level)?;
+ let mut arrow_writer = StreamWriter::try_new(encoder, &batch.schema())?;
Review Comment:
I filed https://github.com/apache/datafusion-comet/issues/1186 for re-using the writer across many batches. It looks like a big perf win.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] [do not review] experimental support for lz4 compression (not working) [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #1181:
URL: https://github.com/apache/datafusion-comet/pull/1181#discussion_r1890865548
##########
native/core/src/execution/shuffle/shuffle_writer.rs:
##########
@@ -1543,14 +1569,38 @@ pub(crate) fn write_ipc_compressed<W: Write + Seek>(
// write ipc_length placeholder
output.write_all(&[0u8; 8])?;
- // write ipc data
- // TODO: make compression level configurable
- let mut arrow_writer = StreamWriter::try_new(zstd::Encoder::new(output, 1)?, &batch.schema())?;
- arrow_writer.write(batch)?;
- arrow_writer.finish()?;
+ let output = match codec {
+ CompressionCodec::Lz4 => {
+ // write IPC first without compression
+ let mut buffer = vec![];
+ let mut arrow_writer = StreamWriter::try_new(&mut buffer, &batch.schema())?;
+ arrow_writer.write(batch)?;
+ arrow_writer.finish()?;
+ let ipc_encoded = arrow_writer.into_inner()?;
+
+ let mut encoder = lz4::EncoderBuilder::new()
+ .content_size(ipc_encoded.len() as u64)
+ .checksum(ContentChecksum::ChecksumEnabled)
+ .block_checksum(BlockChecksum::BlockChecksumEnabled)
+ .level(4)
+ .block_size(BlockSize::Default)
+ .auto_flush(true)
+ .build(&mut *output)?;
+ encoder.write_all(ipc_encoded.as_slice())?;
+ let (output, result) = encoder.finish();
+ result?;
+ output
+ }
+ CompressionCodec::Zstd(level) => {
+ let encoder = zstd::Encoder::new(output, *level)?;
+ let mut arrow_writer = StreamWriter::try_new(encoder, &batch.schema())?;
Review Comment:
To add some more context here, we buffer rows per partition until we reach the desired batch size and then need to serialize that batch to bytes that can be read as one block by `CometBlockStoreShuffleReader`.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org