Skip to content

Conversation

@xinyiZzz
Copy link
Contributor

@xinyiZzz xinyiZzz commented Nov 23, 2021

Proposed changes

  1. Add thread local variable TheadContext, save task info, MemTracker, etc.;
  2. Implement a new memory statistics framework based on TCMalloc Hook and TheadContext, and it is expected that all memory consume/release of the BE process can be counted; (Introduction: https://shimo.im/docs/DT6JXDRkdTvdyV3G)
  3. Refactor MemTracker, streamline the code, and adapt to the new statistical framework;
  4. Add Task MemTracker Pool, manage all Query, Load, and Compaction tasks on BE, a Task ID is unique in the BE process, and judge whether it exceeds the Query memory limit based on the sum of the memory consumption of all fragments of a Task.
    (Unlike before, The query memory limit was previously used as a fragment instance level limit. Therefore, some previously successful large queries may fail, and the query memory limit configuration needs to be increased.)
  5. Add new Process MemTracker, ChunkAllocator MemTracker, and modify the memory statistics method of MemPool and BufferPool.

[ impact of testing on performance ]
The current default untracked_mem_limit_mbytes = 1M, the test found no impact on performance
Config untracked_mem_limit_mbytes impact on performance:
master, jmeter thread=50, Avg1: 23120, Avg2: 22505, Avg3: 23459
untracked_mem_limit_mbytes=4M, jmeter thread=50, Avg1: 23024, Avg2: 23391 22681
untracked_mem_limit_mbytes=2M, jmeter thread=50, Avg1: 23426, Avg2: 22674 23658
untracked_mem_limit_mbytes=64K, jmeter thread=50, Avg1: 24121, Avg2: 24042 23762 22939 23294
untracked_mem_limit_mbytes=4K, jmeter thread=50, Avg1: 24942, Avg2: 24983 23305 22611 23506

Types of changes

What types of changes does your code introduce to Doris?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Code refactor (Modify the code structure, format the code, etc...)
  • Optimization. Including functional usability improvements and performance improvements.
  • Dependency. Such as changes related to third-party components.
  • Other.

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have created an issue on (Fix [Feature] Refactored memory statistics framework MemTracker #7196) and described the bug/feature there in detail
  • Compiling and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • If these changes need document changes, I have updated the document
  • Any dependent changes have been merged

Further comments

If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...

@xinyiZzz xinyiZzz force-pushed the thread_local branch 3 times, most recently from bee0e2d to d99cf05 Compare November 30, 2021 06:43
@EmmyMiao87
Copy link
Contributor

Why does this parameter 'untracked_mem_limit_mbytes' affect performance?
What is your data and table meta?

fmt::format(detail, BackendOptions::get_localhost(), print_id(_fragment_instance_id),
std::to_string(_query_mem_tracker.lock()->consumption()),
std::to_string(_query_mem_tracker.lock()->limit()));
ExecEnv::GetInstance()->fragment_mgr()->cancel(
Copy link
Contributor

Choose a reason for hiding this comment

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

Here loses the thread context and cannot cancel immediately.
The operator will continue to run until the flag is checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will pay attention to the problem that PlanFragmentExecutor::cancel cannot cancel instance in time.

After that, can consider printing the thread context recorded in ThreadContext, but it may be useless, because ThreadMemTracker will accumulate a batch of memory requests to call consume, and the memory request mem_limit_exceeded may be small.
It may be more effective to print the status of the query and all instance trackers.

@xinyiZzz
Copy link
Contributor Author

xinyiZzz commented Dec 8, 2021

Why does this parameter 'untracked_mem_limit_mbytes' affect performance? What is your data and table meta?

Because compared to the previous only consume/release MemTracker for large memory, the consume/release frequency in TCMalloc Hook will be much higher.
This parameter has been renamed to mem_tracker_consume_min_size_mbytes, the comment is clearer

@xinyiZzz xinyiZzz force-pushed the thread_local branch 2 times, most recently from 089c5d1 to fc8210d Compare December 12, 2021 01:59
@xinyiZzz xinyiZzz changed the title [Memory] Use TCMalloc Hook to count the real Process and Query MemTracker [Memory] Refactor MemTracker and new memory statistics framework based on TCMalloc Hook Jan 5, 2022
@xinyiZzz xinyiZzz force-pushed the thread_local branch 3 times, most recently from bd057fe to 023f6d6 Compare January 7, 2022 06:11
CONF_mInt32(remote_storage_read_buffer_mb, "16");

// Whether to initialize TCmalloc new/delete Hook, MemTracker is currently counted in Hook.
CONF_mBool(use_tc_hook, "true");
Copy link
Member

@yangzhg yangzhg Jan 11, 2022

Choose a reason for hiding this comment

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

track_new_delete maybe better, is this can be mutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, thats sounds good

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Refactored memory statistics framework MemTracker

5 participants