-
Notifications
You must be signed in to change notification settings - Fork 485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ORC-817: Replace aircompressor ZStandard compression with zstd-jni #988
Conversation
* Add zstd-jni dependency, and add a new CompressionCodec ZstdCodec that uses it. Add ORC conf to set compression level. * Add ORC conf to use long mode, and add configuration setters for windowLog and longModeEnable. * Add tests that verify the correctness of writing and reading across compression levels, window sizes, and long mode use. * Add test for compatibility between Zstd aircompressor and zstd-jni implementations. * Fix filterWithSeek test with a smaller percentage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be extremely carefully handled, @dchristle .
I'm not considering this at Apache ORC 1.8.0 timeframe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide a performance benchmark result at least.
We need to leave the pure java library as an option with automatic fallback because not every platform will have the native library. Furthermore, if there is a bug in the aircompresssor codec, we may need to configure it for reading old files. I also second Dongjoon's concern about benchmarks. JNI can have a positive impact, but it can also have negative impacts. That is especially true if non-native ByteBuffers (or byte arrays) are used. |
We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable. |
Hi @dchristle , do you have a performance benchmark result? Thanks. |
I did some tests based on this PR. Under the same Spark resources, zstd-jni compression is faster than aircompressor. Here is also a performance comparison. opensearch-project/OpenSearch#9422 (comment) spark
use aircompressoruse zstd-jni |
I think we should be able to achieve this by automatically fallback, such as the following code, org.apache.orc.impl.WriterImpl static {
try {
Native.load();
} catch (UnsatisfiedLinkError | ExceptionInInitializerError e) {
}
}
public static CompressionCodec createCodec(CompressionKind kind) {
...
case ZSTD:
if (Native.isLoaded()) {
return new ZstdCodec();
} else {
return new AircompressorCodec(kind, new ZstdCompressor(),
new ZstdDecompressor());
} |
+1 for that fallback. Could you take over this PR, @cxzl25 ? |
BTW, we need more time to test because |
### What changes were proposed in this pull request? Original PR: #988 Original author: dchristle This PR will support the use of [zstd-jni](https://github.com/luben/zstd-jni) library as the implementation of ORC zstd, with better performance than [aircompressor](https://github.com/airlift/aircompressor). (#988 (comment)) This PR also exposes the compression level and "long mode" settings to ORC users. These settings allow the user to select different speed/compression trade-offs that were not supported by the original aircompressor. - Add zstd-jni dependency, and add a new CompressionCodec ZstdCodec that uses it. Add ORC conf to set compression level. - Add ORC conf to use long mode, and add configuration setters for windowLog. - Add tests that verify the correctness of writing and reading across compression levels, window sizes, and long mode use. - Add test for compatibility between Zstd aircompressor and zstd-jni implementations. ### Why are the changes needed? These change makes sense for a few reasons: ORC users will gain all the improvements from the main zstd library. It is under active development and receives regular speed and compression improvements. In contrast, aircompressor's zstd implementation is older and stale. ORC users will be able to use the entire speed/compression tradeoff space. Today, aircompressor's implementation has only one of eight compression strategies ([link](https://github.com/airlift/aircompressor/blob/c5e6972bd37e1d3834514957447028060a268eea/src/main/java/io/airlift/compress/zstd/CompressionParameters.java#L143)). This means only a small range of faster but less compressive strategies can be exposed to ORC users. ORC storage with high compression (e.g. for large-but-infrequently-used data) is a clear use case that this PR would unlock. It will harmonize the Java ORC implementation with other projects in the Hadoop ecosystem. Parquet, Spark, and even the C++ ORC reader/writers all rely on the official zstd implementation either via zstd-jni or directly. In this way, the Java reader/writer code is an outlier. Detection and fixing any bugs or regressions will generally happen much faster, given the larger number of users and active developer community of zstd and zstd-jni. The largest tradeoff is that zstd-jni wraps compiled code. That said, many microprocessor architectures are already targeted & bundled into zstd-jni, so this should be a rare hurdle. ### How was this patch tested? - Unit tests for reading and writing ORC files using a variety of compression levels, window logs, all pass. - Unit test to compress and decompress between aircompressor and zstd-jni passes. Note that the current aircompressor implementation uses a small subset of levels, so the test only compares data using the default compression settings. ### Was this patch authored or co-authored using generative AI tooling? No Closes #1743 from cxzl25/ORC-817. Lead-authored-by: sychen <[email protected]> Co-authored-by: Dongjoon Hyun <[email protected]> Co-authored-by: David Christle <[email protected]> Co-authored-by: Yiqun Zhang <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
### What changes were proposed in this pull request? Original PR: #988 Original author: dchristle This PR will support the use of [zstd-jni](https://github.com/luben/zstd-jni) library as the implementation of ORC zstd, with better performance than [aircompressor](https://github.com/airlift/aircompressor). (#988 (comment)) This PR also exposes the compression level and "long mode" settings to ORC users. These settings allow the user to select different speed/compression trade-offs that were not supported by the original aircompressor. - Add zstd-jni dependency, and add a new CompressionCodec ZstdCodec that uses it. Add ORC conf to set compression level. - Add ORC conf to use long mode, and add configuration setters for windowLog. - Add tests that verify the correctness of writing and reading across compression levels, window sizes, and long mode use. - Add test for compatibility between Zstd aircompressor and zstd-jni implementations. ### Why are the changes needed? These change makes sense for a few reasons: ORC users will gain all the improvements from the main zstd library. It is under active development and receives regular speed and compression improvements. In contrast, aircompressor's zstd implementation is older and stale. ORC users will be able to use the entire speed/compression tradeoff space. Today, aircompressor's implementation has only one of eight compression strategies ([link](https://github.com/airlift/aircompressor/blob/c5e6972bd37e1d3834514957447028060a268eea/src/main/java/io/airlift/compress/zstd/CompressionParameters.java#L143)). This means only a small range of faster but less compressive strategies can be exposed to ORC users. ORC storage with high compression (e.g. for large-but-infrequently-used data) is a clear use case that this PR would unlock. It will harmonize the Java ORC implementation with other projects in the Hadoop ecosystem. Parquet, Spark, and even the C++ ORC reader/writers all rely on the official zstd implementation either via zstd-jni or directly. In this way, the Java reader/writer code is an outlier. Detection and fixing any bugs or regressions will generally happen much faster, given the larger number of users and active developer community of zstd and zstd-jni. The largest tradeoff is that zstd-jni wraps compiled code. That said, many microprocessor architectures are already targeted & bundled into zstd-jni, so this should be a rare hurdle. ### How was this patch tested? - Unit tests for reading and writing ORC files using a variety of compression levels, window logs, all pass. - Unit test to compress and decompress between aircompressor and zstd-jni passes. Note that the current aircompressor implementation uses a small subset of levels, so the test only compares data using the default compression settings. ### Was this patch authored or co-authored using generative AI tooling? No Closes #1743 from cxzl25/ORC-817. Lead-authored-by: sychen <[email protected]> Co-authored-by: Dongjoon Hyun <[email protected]> Co-authored-by: David Christle <[email protected]> Co-authored-by: Yiqun Zhang <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]> (cherry picked from commit 33be571) Signed-off-by: Dongjoon Hyun <[email protected]>
What changes were proposed in this pull request?
This PR proposes to replace the
aircompressor
library for ORC's ZStandard compression withzstd-jni
, which is a set of JNI bindings around the officialzstd
library. In addition to switching the underlying library, this PR also exposes the compression level and "long mode" settings to ORC users. These settings allow user choice around different speed/compression tradeoffs, rather than the current approach that primarily uses a default setting.Why are the changes needed?
These change makes sense for a few reasons:
zstd
library. It is under active development and receives regular speed and compression improvements. In contrast,aircompressor
's zstd implementation is older and stale.aircompressor
's implementation has only one of eight compression strategies (link). This means only a small range of faster but less compressive strategies can be exposed to ORC users. ORC storage with high compression (e.g. for large-but-infrequently-used data) is a clear use case that this PR would unlock.zstd
implementation either viazstd-jni
or directly. In this way, the Java reader/writer code is an outlier.zstd
andzstd-jni
.The largest tradeoff is that
zstd-jni
wraps compiled code. That said, many microprocessor architectures are already targeted & bundled intozstd-jni
, so this should be a rare hurdle.Open issues:
CompressionCodec
interface seems limited to exposing an enum with 3 options for speed, e.g.FAST
orDEFAULT
, and other codec-specific configs don't have a clear way to make it down into the codec implementation itself. I think we want to allow users to set the actual level as an integer, and to specify the window log size & long mode boolean as they wish. It wasn't clear how I could communicate these confs down to the lower levelZstdCodec
within the bounds of the existingCompressionCodec
interface. Right now, I used a hack to get the codec to read the conf options.DirectByteBuffer
handling case. Right now, each call is treated the same way and will incur unnecessary copying if the inputByteBuffer
is direct.zstd-jni
should have superior performance across the board, it's important to actually measure that with the benchmark suite.List of changes:
Add zstd-jni dependency, and add a new CompressionCodec ZstdCodec that uses it. Add ORC conf to set compression level.
Add ORC conf to use long mode, and add configuration setters for windowLog and longModeEnable.
Add tests that verify the correctness of writing and reading across compression levels, window sizes, and long mode use.
Add test for compatibility between Zstd aircompressor and zstd-jni implementations.
Fix filterWithSeek test with a smaller percentage.
Minor formatting and spelling fixes.
How was this patch tested?
aircompressor
andzstd-jni
passes. Note that the currentaircompressor
implementation uses a small subset of levels, so the test only compares data using the default compression settings.@dongjoon-hyun @wgtmac