Skip to content
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

Soft memory limits for merges and mutations. #45710

Closed
alexey-milovidov opened this issue Jan 27, 2023 · 1 comment · Fixed by #46089
Closed

Soft memory limits for merges and mutations. #45710

alexey-milovidov opened this issue Jan 27, 2023 · 1 comment · Fixed by #46089

Comments

@alexey-milovidov
Copy link
Member

Use case

A user can specify too large background_pool_size, and merges can constantly fail and make no progress due to memory exhaustion.

Horizontal merges of wide tables with many LowCardinality or AggregateFunction columns can have high memory usage.

Mutations can have high memory usage if they use complex expressions for updating or deleting.

We should not let too many merges be processed at once if the memory usage is high.

Implementation proposal

Add two global configuration options:

merges_memory_usage_soft_limit and merges_memory_usage_soft_limit_to_ram_ratio

similarly to max_server_memory_usage and max_server_memory_usage_to_ram_ratio. The latter setting should be 0.5 by default.

Track the total memory usage by merges.

Caveat: it cannot be done with MemoryTracker. Because a merge operation can free some memory (primary keys) that were allocated outside of the context of the merge, the resulting memory usage at the end of the merge can be negative. We cannot reset it to zero at the end of the merge operation because the MemoryTracker of the merge is attached to the server's global MemoryTracker and should be consistent with it. The only reasonable way is to track the sum of memory usage by active merges separately.

If the current memory usage by merges is higher than the soft limit, do not start new merges.

@novikd
Copy link
Member

novikd commented May 18, 2023

Implemented in #48787.

@novikd novikd closed this as completed May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants