-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Significantly decrease MemoryTracking drift #16121
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
Merged
alexey-milovidov
merged 10 commits into
ClickHouse:master
from
azat:total_memory_tracker-by-default
Oct 24, 2020
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
72d7b61
Use total_memory_tracker when there is no other MemoryTracker object.
azat 114ea9b
Fix accounting for new/delete from different threads for VariableCont…
azat 0cccf30
Fix parent memory tracker during query detaching
azat 6c42ad5
Add a test for MemoryTracking drift
azat 3f594ed
Add a test for memory drift in user memory tracker (max_memory_usage_…
azat 6e5b04f
Make 01540_MemoryTracking integration
azat 96da5f6
Disable syncing MemoryTracking with RSS for test_MemoryTracking
azat c3c6ac3
Tune TTL of the background query in 01541_max_memory_usage_for_user
azat e00f6c4
Merge branch 'master' into total_memory_tracker-by-default
alexey-milovidov 34b9d15
Update ThreadStatusExt.cpp
alexey-milovidov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
4 changes: 4 additions & 0 deletions
4
tests/integration/test_MemoryTracking/configs/asynchronous_metrics_update_period_s.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <yandex> | ||
| <!-- this update period also syncs MemoryTracking with RSS, disable this, by using period = 1 day --> | ||
| <asynchronous_metrics_update_period_s>86400</asynchronous_metrics_update_period_s> | ||
| </yandex> |
7 changes: 7 additions & 0 deletions
7
tests/integration/test_MemoryTracking/configs/no_system_log.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <yandex> | ||
| <metric_log remove="remove"/> | ||
| <query_masking_rules remove="remove"/> | ||
| <query_thread_log remove="remove"/> | ||
| <text_log remove="remove"/> | ||
| <trace_log remove="remove"/> | ||
| </yandex> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # pylint: disable=unused-argument | ||
| # pylint: disable=redefined-outer-name | ||
| # pylint: disable=line-too-long | ||
|
|
||
| import logging | ||
| import pytest | ||
| from helpers.cluster import ClickHouseCluster | ||
|
|
||
| cluster = ClickHouseCluster(__file__) | ||
|
|
||
| node = cluster.add_instance('node', main_configs=[ | ||
| 'configs/no_system_log.xml', | ||
| 'configs/asynchronous_metrics_update_period_s.xml', | ||
| ]) | ||
|
|
||
| logging.getLogger().setLevel(logging.INFO) | ||
| logging.getLogger().addHandler(logging.StreamHandler()) | ||
|
|
||
| @pytest.fixture(scope='module', autouse=True) | ||
| def start_cluster(): | ||
| try: | ||
| cluster.start() | ||
| yield cluster | ||
| finally: | ||
| cluster.shutdown() | ||
|
|
||
| query_settings = { | ||
| 'max_threads': 1, | ||
| 'query_profiler_real_time_period_ns': 0, | ||
| 'query_profiler_cpu_time_period_ns': 0, | ||
| 'log_queries': 0, | ||
| } | ||
| sample_query = "SELECT groupArray(repeat('a', 1000)) FROM numbers(10000) GROUP BY number%10 FORMAT JSON" | ||
|
|
||
| def query(*args, **kwargs): | ||
| if 'settings' not in kwargs: | ||
| kwargs['settings'] = query_settings | ||
| else: | ||
| kwargs['settings'].update(query_settings) | ||
| return node.query(*args, **kwargs) | ||
| def http_query(*args, **kwargs): | ||
| if 'params' not in kwargs: | ||
| kwargs['params'] = query_settings | ||
| else: | ||
| kwargs['params'].update(query_settings) | ||
| return node.http_query(*args, **kwargs) | ||
|
|
||
| def get_MemoryTracking(): | ||
| return int(http_query("SELECT value FROM system.metrics WHERE metric = 'MemoryTracking'")) | ||
|
|
||
| def check_memory(memory): | ||
| # 3 changes to MemoryTracking is minimum, since: | ||
| # - this is not that high to not detect inacuracy | ||
| # - memory can go like X/X+N due to some background allocations | ||
| # - memory can go like X/X+N/X, so at least 2 changes | ||
| changes_allowed = 3 | ||
| # if number of samples is large enough, use 10% from them | ||
| # (actually most of the time there will be only few changes, it was made 10% to avoid flackiness) | ||
| changes_allowed_auto=int(len(memory) * 0.1) | ||
| changes_allowed = max(changes_allowed_auto, changes_allowed) | ||
|
|
||
| changed=len(set(memory)) | ||
| logging.info('Changes: allowed=%s, actual=%s, sample=%s', | ||
| changes_allowed, changed, len(memory)) | ||
| assert changed < changes_allowed | ||
|
|
||
| def test_http(): | ||
| memory = [] | ||
| memory.append(get_MemoryTracking()) | ||
| for _ in range(100): | ||
| http_query(sample_query) | ||
| memory.append(get_MemoryTracking()) | ||
| check_memory(memory) | ||
|
|
||
| def test_tcp_multiple_sessions(): | ||
| memory = [] | ||
| memory.append(get_MemoryTracking()) | ||
| for _ in range(100): | ||
| query(sample_query) | ||
| memory.append(get_MemoryTracking()) | ||
| check_memory(memory) | ||
|
|
||
| def test_tcp_single_session(): | ||
| memory = [] | ||
| memory.append(get_MemoryTracking()) | ||
| sample_queries = [ | ||
| sample_query, | ||
| "SELECT metric, value FROM system.metrics WHERE metric = 'MemoryTracking'", | ||
| ] * 100 | ||
| rows = query(';'.join(sample_queries)) | ||
| memory = rows.split('\n') | ||
| memory = filter(lambda x: x.startswith('MemoryTracking'), memory) | ||
| memory = map(lambda x: x.split('\t')[1], memory) | ||
| memory = [*memory] | ||
| check_memory(memory) |
5 changes: 5 additions & 0 deletions
5
tests/queries/0_stateless/01541_max_memory_usage_for_user.reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| HTTP | ||
| TCP_ONE_SESSION | ||
| TCP | ||
| OK | ||
| KILL sleep |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Don't understand this change.
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.
Ok.