Skip to content

Reduce memory usage in writer with more memory efficient output buffer implementation #24913

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

chenyangfb
Copy link
Contributor

@chenyangfb chenyangfb commented Apr 14, 2025

Description

Currently ChunkedSliceOutput is used for storing compressed output in writer. It managed list of buffers with size of power of 2 (e.g. 8k, 16k, 32k), and reuse buffers after flushing. It could leads to extra memory usage and OOM due to 1) mismatch in compressed output size and buffer size, 2) reusing buffers and not freeing buffers leads to extra memory usage by design.

Common scenario which leads to OOM includes

  1. large number of streams with small amount of data (100k stream with 1k compressed bytes), each using minimal buffer size (e.g. 8k)
  2. Each stream is wasting half of largest buffer (e.g. 8M out of 16M buffer)
  3. Writer memory usage is high even after flushing (Reduce memory usage in writer by freeing unused buffers #23724 support freeing unused buffer in chunk supplier during reset)

This PR introduce OrcLazyChunkedOutputBuffer which focus on avoiding used memory.

  1. Create buffer size based on the size of compressed output, this avoid the issue 1) and 2) mentioned above
  2. lazy initialization in OrcLazyChunkedOutputBuffer and OrcOutputBuffer
  3. Reset all the closed buffers, only keep the active buffer.

This behavior is controlled by lazyOutputBuffer in OrcWriterOptions, and it's disabled by default.

Impact

Reduce memory usage in writer.

Test Plan

Tested with Spark workload with high memory usage.
~10% improvement in run time and resource usage (memory reservation time), reduced GC time.
Tested with general Spark workload
No change in cpu time, slight reduction in run time and GC time.

Release Notes

General change
Reduce memory usage in writer with more memory efficient output buffer implementation

@chenyangfb chenyangfb force-pushed the orc_output_buffer branch 2 times, most recently from b400461 to b75ec9b Compare April 14, 2025 16:21
@chenyangfb chenyangfb force-pushed the orc_output_buffer branch 2 times, most recently from b88e026 to 04a0df7 Compare April 14, 2025 17:13
@chenyangfb chenyangfb changed the title Add OrcLazyChunkedOutputBuffer which is more memory efficient Reduce memory usage in writer with more memory efficient output buffer implementation Apr 14, 2025
@chenyangfb chenyangfb marked this pull request as ready for review April 14, 2025 18:18
@chenyangfb chenyangfb requested review from sdruzkin and a team as code owners April 14, 2025 18:18
@chenyangfb chenyangfb requested a review from presto-oss April 14, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant