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
GODRIVER-3132 Use dst buf pool for zstd encoding. #1577
base: v1
Are you sure you want to change the base?
Conversation
API Change ReportNo changes found! |
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.
LGTM!
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 change doesn't directly address the problem described in GODRIVER-3132, which is that each zstd.Encoder
allocates a bunch of memory and then never releases it. The best way to limit that "permanent" allocated memory seems to be using WithWindowSize to limit the max window size. Additionally, klauspost/compress v1.17.5 limits the max window size for better/best Zstd compression to 8MB, so it may be worth updating to that version or newer.
ptr := zstdBufPool.Get().(*[]byte) | ||
b := encoder.EncodeAll(in, *ptr) |
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.
Instead of adding an additional pool of buffers just for Zstd compression, can we leverage the existing op buffer pool to improve memory usage for all compression types?
For example, in compression.go
, change CompressPayload
to accept a destination byte slice:
func CompressPayload(src, dst []byte, opts CompressionOpts) ([]byte, error) {
// ...
return encoder.EncodeAll(src, dst)
// ...
Then in connection.go
, pass the existing destination byte slice into CompressPayload
:
func (c *Connection) CompressWireMessage(src, dst []byte) ([]byte, error) {
// ...
compressed, err := driver.CompressPayload(rem, dst, opts)
// ...
Then remove the following call to AppendCompressedCompressedMessage
, which is just an alias for append
.
GODRIVER-3132
Summary
Use a pool to reuse the dst buffer for
zstd.EncodeAll
.benchstat results: