-
Notifications
You must be signed in to change notification settings - Fork 410
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
MemoryTracker*: Use std::shared_ptr to manage MemoryTracker. #5765
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
/run-all-tests |
/run-all-tests |
Coverage for changed files
Coverage summary
full coverage report (for internal network access only) |
@@ -139,7 +139,7 @@ class SegmentReadTaskPool : private boost::noncopyable | |||
, log(&Poco::Logger::get("SegmentReadTaskPool")) | |||
, unordered_input_stream_ref_count(0) | |||
, exception_happened(false) | |||
, mem_tracker(current_memory_tracker) | |||
, mem_tracker(current_memory_tracker == nullptr ? nullptr : current_memory_tracker->shared_from_this()) |
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.
When will segReadTaskPool be destructed? Is it shared by multiple MPPTasks?
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.
SegmentReadTaskPool
will be destructed after inputstreams which returned by DeltaMergeStore::read
are destructed.
One SegmentReadTaskPool
object will be created for each DeltaMergeStore::read
function call. It is not shared by multiple MPPTasks.
MemoryTracker memory_tracker; | ||
memory_tracker.setMetric(CurrentMetrics::MemoryTrackingInBackgroundProcessingPool); | ||
current_memory_tracker = &memory_tracker; | ||
auto memory_tracker = MemoryTracker::create(); |
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.
Is this a test code? since this memTracker did not setNext
a root memTracker.
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.
This seems not a test code.
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.
These are the background threads that handle background tasks such as compaction and delta merge.
What is the use of setNext
a root MemoryTracker?
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.
Root memtracker is total_mem_tracker in ProcessLsit.
if not setNext
a root memtracker,the memory usage actually not be detected by process level of TiFlash.
The config max_memory_usage_for_all_queries
will not work on it.
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.
These are the background threads that handle background tasks such as compaction and delta merge.
What is the use of
setNext
a root MemoryTracker?
ref:https://pingcap.feishu.cn/wiki/wikcnvA5vz6Mfk9VocSssEqPp3b
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.
No. It just do some background tasks, such as delta comapction, delta merge, segment split, segment merge.
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.
Since segment's size is not very large, the average is about 1GB, it doesn't consume a lot of memory.
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.
Root memtracker is total_mem_tracker in ProcessLsit.
if not setNext a root memtracker,the memory usage actually not be detected by process level of TiFlash.
The config max_memory_usage_for_all_queries will not work on it.
The memory used in here is not caused by queries, so I think it should not be a child of the ProcessList::total_mem_tracker
(limited by max_memory_usage_for_all_queries
).
But we do need another root MemoryTracker for all background tasks and maybe a new config item for controlling the memory usage for it.
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.
if there are two root memTrackers,none of them can track all the memory of the tiflash process. In that case,we can't track and throttle the process memory. I think we can use a special user level memory tracker to tracker the background storage mem usage, and expose a setting to user, so that it can be tracked and throttled
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.
- I agree that a root memory tracker that track all memory of a TiFlash instance can avoid OOM under some case. But it is weird that config with the name
max_memory_usage_for_all_queries
limit the memory usage for non-queries task. Maybe we need to refactor the config ;) - Some background tasks are lower priority than queries, so those background tasks can be delayed or canceled if the total memory usage reaches the high water mark. We need another bg_tasks_memory_tracker besides queires_memory_tracker.
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.
lgtm
@windtalker PTAL |
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.
LGTM
/merge |
@JinheLin: It seems you want to merge this PR, I will help you trigger all the tests: /run-all-tests You only need to trigger If you have any questions about the PR merge process, please refer to pr process. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
This pull request has been accepted and is ready to merge. Commit hash: 6fdcf6c
|
Coverage for changed files
Coverage summary
full coverage report (for internal network access only) |
What problem does this PR solve?
Issue Number: ref #5689
What is changed and how it works?
MemoryTracker
to track memory usage ofMPPTask
. And also usesMemoryTracker
to estimate the size of the data and different execution strategies, such as multi-thread or single-thread, are adopted for different data sizes.MemoryTracker
object of the correspondingMPPTask
tocurrent_memory_tracker
when reading data and avoid inaccurate data size estimates.MPPTask
exists, the correspondingMemoryTracker
will be destroyed. But the reading threads of storage can still use this object and cause the process crash.shared_ptr
ofMemoryTracker
instead of a raw pointer.MemoryTracker
objects byMemoryTracker::create
which returns astd::shared_ptr<MemoryTracker>
object.DeltaMerge::read
,SegmentReadTaskPool
will callcurrent_memory_tracker->shared_from_this()
to get the shared pointer.Check List
Tests
Side effects
Documentation
Release note