Skip to content

Rework total memory tracker#10362

Merged
alexey-milovidov merged 3 commits intomasterfrom
rework-total-memory-tracker
Apr 20, 2020
Merged

Rework total memory tracker#10362
alexey-milovidov merged 3 commits intomasterfrom
rework-total-memory-tracker

Conversation

@alexey-milovidov
Copy link
Member

@alexey-milovidov alexey-milovidov commented Apr 19, 2020

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Added a setting max_server_memory_usage to limit total memory usage of the server. The metric MemoryTracking is now calculated without a drift. The setting max_memory_usage_for_all_queries is now obsolete and does nothing. This closes #10293. Note: on servers with very low memory amount and swap you may have to add max_server_memory_usage_to_ram_ratio in config.xml and set it to a value larger than one.

@alexey-milovidov alexey-milovidov added pr-improvement Pull request with some product improvements doc-alert labels Apr 19, 2020
@alexey-milovidov alexey-milovidov force-pushed the rework-total-memory-tracker branch from 566c79b to 1eb3080 Compare April 19, 2020 22:10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Only has meaning at server startup. will be better (like other settings has)?

@azat
Copy link
Member

azat commented Apr 19, 2020

(And just a note it includes #10361)

@alexey-milovidov alexey-milovidov force-pushed the rework-total-memory-tracker branch from a080e15 to 3755a5b Compare April 19, 2020 22:59
@alexey-milovidov alexey-milovidov merged commit 7e5b044 into master Apr 20, 2020
@alexey-milovidov alexey-milovidov deleted the rework-total-memory-tracker branch April 20, 2020 03:16
\
M(SettingUInt64, max_memory_usage, 0, "Maximum memory usage for processing of single query. Zero means unlimited.", 0) \
M(SettingUInt64, max_memory_usage_for_user, 0, "Maximum memory usage for processing all concurrently running queries for the user. Zero means unlimited.", 0) \
M(SettingUInt64, max_memory_usage_for_all_queries, 0, "Maximum memory usage for processing all concurrently running queries on the server. Zero means unlimited.", 0) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually max_memory_usage_for_all_queries can be useful to (to limit the memory usage for all queries except specific, by overwriting max_memory_usage_for_all_queries to 0), but I guess max_memory_usage_for_user can be used instead (but will require more attention, since there is default user).

@alexey-milovidov
Copy link
Member Author

My collegue @velom from Yandex.Metrica requested (he is too shy to post a comment on GitHub) that max_server_memory_usage should be server setting in config.xml instead of user-level setting. Will do.

@azat
Copy link
Member

azat commented Apr 20, 2020

max_server_memory_usage should be server setting in config.xml instead of user-level setting. Will do.

Maybe reintroducing max_memory_usage_for_all_queries for this particular case will be better? (not sure though)

@azat
Copy link
Member

azat commented Apr 22, 2020

This PR makes ClickHouseMetrics_MemoryTracking grows on and on (after some time it >10TB, and it does not stops growing), while ClickHouseAsyncMetrics_MemoryResident is ok (after some time it is in between 300-600GB), any thoughts?

@alexey-milovidov
Copy link
Member Author

We cannot longer calculate this metric in incremental fashion - should reset it in the same way as total_memory_tracker.

@alexey-milovidov
Copy link
Member Author

alexey-milovidov commented Apr 22, 2020

Why it grows?

Because memory is deallocated in a context where there is no CurrentThread and total_memory_tracker. I planned try to make it used in every context. It should be a simple change but care should be taken... Maybe you can also try to make this change?

Also worth to note that we cannot calculate 100% consistently.

@azat
Copy link
Member

azat commented Apr 22, 2020

Maybe you can also try to make this change?

Sure, I will take a look if you will not fix it by that time

@zlobober
Copy link
Contributor

zlobober commented Jun 21, 2020

By reading this topic, I understood follwing; please correct me if I am wrong:

  1. max_memory_usage_for_all_queries is now obsolete;
  2. max_memory_usage & max_memory_usage_for_user are still working;
  3. max_server_memory_usage is now an intended way to prevent server from running out of memory;
  4. ClickHouseMetrics_MemoryTracking is now broken and allows unlimited drift;
  5. There is plan of fixing ClickHouseMetrics_MemoryTracking described in Rework total memory tracker #10362 (comment), but nobody have done that yet.

I am interested in this topic because we are using CH as a library in third-party application, and it would definitely be great to be able to explicitly measure CH runtime memory separately from the rest of RSS for monitoring purposes. Expressing it as (RSS) minus (the rest of 'known' memory) may hide memory-related issues in ClickHouse code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Total memory tracker should account all server memory usage, not only queries.

3 participants