-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix ZStandard native memory leaks #14087
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
Conversation
Signed-off-by: Ludovic Orban <[email protected]>
joakime
left a comment
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.
Simple enough.
Signed-off-by: Ludovic Orban <[email protected]>
Signed-off-by: Ludovic Orban <[email protected]>
…ative resources even when the sink does not do a last write or the source is not read until EOF nor failed Signed-off-by: Ludovic Orban <[email protected]>
Signed-off-by: Ludovic Orban <[email protected]>
…Pool maxCapacity Signed-off-by: Ludovic Orban <[email protected]>
joakime
left a comment
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.
I don't like the reduction in recommended default size.
Can we instead have a log warning be produced if the bufferPool isn't setup properly to allow for zstandard lib recommendations?
| // but put some upper limit on it for our default buffer size. | ||
| // The user can still configure the buffer size to be higher if they want to. | ||
| long bufferSizeCeiling = 256_000; | ||
| long bufferSizeCeiling = 64 * 1024L; // TODO this is the default ArrayByteBufferPool maxCapacity, there should be a way to discover that |
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 size is smaller than the recommended size by the zstandard lib.
| // but put some upper limit on it for our default buffer size. | ||
| // The user can still configure the buffer size to be higher if they want to. | ||
| long bufferSizeCeiling = 256_000; | ||
| long bufferSizeCeiling = 64 * 1024L; // TODO this is the default ArrayByteBufferPool maxCapacity, there should be a way to discover that |
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 size is smaller than the recommended size by the zstandard lib.
|
@joakime we currently have no API to detect the maximum pooled buffer size, so if we were to warn "please make sure your pool is properly configured" we'd always do it, even when the pool is properly configured. I hardcoded 64 KB here because the default maximum pooled buffer size is 64 KB, and it is the only solution that is both quick and easy to do that I could think of. If zstd were to use non-pooled buffer, the performance would go down the drain: each direct byte buffer object has to be finalized (requires enqueuing/dequeuing from a concurrent queue, expensive!) and each time a new buffer is allocated it has to be zero'ed (filling 132 KB of memory with zeros, expensive!). I agree this solution isn't ideal, but the only alternative I can come up that doesn't require modifying the |
…B buffers Signed-off-by: Ludovic Orban <[email protected]>
… size from its config instead like gzip and brotli already do Signed-off-by: Ludovic Orban <[email protected]>
…B buffers Signed-off-by: Ludovic Orban <[email protected]>
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java
Outdated
Show resolved
Hide resolved
|
Reading https://datatracker.ietf.org/doc/html/rfc8878#section-3.1.1.1.2, the min window size can be just 1 KiB. I think it's best for us to stick with a smaller size like 64 KiB, and document the implications with the |
…oc ByteBufferPool implications of changing the default Signed-off-by: Ludovic Orban <[email protected]>
|
So I've reverted to capping the zstd buffer sizes to 64 KB, and I added a comment to the javadoc explaining that this setting has implications on the I believe this is the most reasonable thing to do for now as a user can always manually set the buffer size. |
Signed-off-by: Ludovic Orban <[email protected]>
|
The zstandard requirements are Of which, ...
https://github.com/facebook/zstd/wiki/Using-libzstd-in-a-memory-constrained-environment |
|
We use the It recommends using 128KB for the Window Size if dealing with sub 2GB inputs on non-streaming modes (we don't use the streaming modes). |
...ession/jetty-compression-common/src/main/java/org/eclipse/jetty/compression/Compression.java
Show resolved
Hide resolved
Signed-off-by: Ludovic Orban <[email protected]>
Signed-off-by: Ludovic Orban <[email protected]>
Signed-off-by: Ludovic Orban <[email protected]>
|
@joakime @sbordet I've reverted the code changes related to the zstd buffer size and left the issue as-is for now, with only changes to the javadoc to hint at the problem. This isn't a regression as this problem exists since the introduction of zstd (de)compression and we need the other fixes to be included in the next release that has to be cut this week, so let's postpone the buffer problem to the next release and simply ignore it for now. |
… its own buffer internally and we only use the configured buffer size to control the buffer receiving (de)compressed data + fix bug in continueOp() buffer rollback logic Signed-off-by: Ludovic Orban <[email protected]>
joakime
left a comment
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.
The current PR is invalid for zstandard, and will break it.
...-zstandard/src/main/java/org/eclipse/jetty/compression/zstandard/ZstandardDecoderConfig.java
Show resolved
Hide resolved
...etty-compression-gzip/src/test/java/org/eclipse/jetty/compression/gzip/AbstractGzipTest.java
Show resolved
Hide resolved
...y-compression-gzip/src/test/java/org/eclipse/jetty/compression/gzip/GzipCompressionTest.java
Show resolved
Hide resolved
Signed-off-by: Ludovic Orban <[email protected]>
Signed-off-by: Ludovic Orban <[email protected]>
Signed-off-by: Ludovic Orban <[email protected]>
joakime
left a comment
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.
Good, for now.
We need a new issue to track the ByteBufferPool changes to make it expose it's limits.
…028-native-leak-zstd
Signed-off-by: Ludovic Orban <[email protected]>
Fixes #14028 by closing the zstd context when sources / sinks are released or when the GC cleans them up.
Also add buffer pooling to the zstd streams.