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

Improve memtrack #5610

Merged
merged 75 commits into from
Aug 31, 2022
Merged

Improve memtrack #5610

merged 75 commits into from
Aug 31, 2022

Conversation

bestwoody
Copy link
Contributor

@bestwoody bestwoody commented Aug 11, 2022

What problem does this PR solve?

Issue Number: close #5609

Problem Summary:

What is changed and how it works?

Solve the following problems which may cause memory quota not working, in order to reduce OOM cases.

1.Track some kind of object was not tracked before, such as object generated by Protobuf.
2.Fix a bug in memtracker, which causes memory quota not working.
3.Fix bugs in our MPPTask construct/destruct logic, which cause memtracker can‘t be propagated into MPPTunnel & ExchangeReceiver
4. Use a background thread to collect RSS metric periodicaly and check how much it exceed the user setting limit in mem tracker. And throttle when it's too large, to control those un-trackable memory such as: cache used by Allocator 、stack allocated by threads.

How RSS check works:
Besides a simply condition check RSS > limit + 5GB. A dynamic linear check logic is also defined.
An example for how this logic works: if limit is 30GB, and real_rss is 40GB, since then mem alloc will fail when tracked amount > 25GB(30-(10-5)=25), when memory usage turn down below 25GB, all query tasks can continue work, where there is no need to wait the real_rss metric updated in next collect 100ms period. The larger real_rss over than limit+5GB, the lower ceiling of memory tracked amount where we can continue allocating memory.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Aug 11, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • windtalker
  • yibin87

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 11, 2022
@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: da1eb24

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Aug 31, 2022
@bestwoody
Copy link
Contributor Author

/rebuild

@bestwoody
Copy link
Contributor Author

/run-all-tests

@ti-chi-bot
Copy link
Member

@bestwoody: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

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.

@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Aug 31, 2022
@bestwoody
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

@bestwoody: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

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.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 102938c

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Aug 31, 2022
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Aug 31, 2022
@bestwoody
Copy link
Contributor Author

/run-all-tests

@bestwoody
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

@bestwoody: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

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.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 512b177

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Aug 31, 2022
@sre-bot
Copy link
Collaborator

sre-bot commented Aug 31, 2022

Coverage for changed files

Filename                                             Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Common/BackgroundTask.cpp                                 17                 2    88.24%           5                 0   100.00%          54                 5    90.74%          10                 3    70.00%
Common/BackgroundTask.h                                    2                 0   100.00%           2                 0   100.00%           4                 0   100.00%           0                 0         -
Common/MPMCQueue.h                                        99                 2    97.98%          37                 0   100.00%         214                 5    97.66%          62                 5    91.94%
Common/MemoryTracker.cpp                                 102                12    88.24%          14                 1    92.86%         163                27    83.44%          68                15    77.94%
Common/MemoryTracker.h                                    14                 6    57.14%          14                 6    57.14%          17                 9    47.06%           0                 0         -
Common/tests/gtest_memtracker.cpp                         58                21    63.79%           3                 0   100.00%          72                 0   100.00%          12                12     0.00%
Flash/Coprocessor/DAGContext.cpp                          98                34    65.31%          27                 6    77.78%         178                44    75.28%          66                35    46.97%
Flash/Coprocessor/DAGContext.h                            37                 9    75.68%          28                 7    75.00%          85                22    74.12%          12                 6    50.00%
Flash/Coprocessor/StreamWriter.h                          10                10     0.00%           5                 5     0.00%          16                16     0.00%           4                 4     0.00%
Flash/Coprocessor/StreamingDAGResponseWriter.cpp         137                27    80.29%          13                 1    92.31%         311                63    79.74%          92                23    75.00%
Flash/Mpp/ExchangeReceiver.cpp                           454               278    38.77%          35                23    34.29%         623               355    43.02%         226               162    28.32%
Flash/Mpp/ExchangeReceiver.h                              14                 2    85.71%          12                 2    83.33%          26                 6    76.92%           2                 0   100.00%
Flash/Mpp/GRPCReceiverContext.cpp                         49                16    67.35%          21                10    52.38%         120                57    52.50%          26                11    57.69%
Flash/Mpp/GRPCReceiverContext.h                            3                 1    66.67%           3                 1    66.67%           5                 1    80.00%           0                 0         -
Flash/Mpp/MPPReceiverSet.cpp                              19                 7    63.16%           6                 2    66.67%          31                11    64.52%          14                 7    50.00%
Flash/Mpp/MPPReceiverSet.h                                 1                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
Flash/Mpp/MPPTask.cpp                                    527               214    59.39%          27                 8    70.37%         480               188    60.83%         194               122    37.11%
Flash/Mpp/MPPTunnel.cpp                                  391                76    80.56%          24                 1    95.83%         332                50    84.94%         150                43    71.33%
Flash/Mpp/MPPTunnel.h                                     25                 4    84.00%          22                 4    81.82%          42                 8    80.95%           2                 0   100.00%
Flash/Mpp/MPPTunnelSet.cpp                                63                40    36.51%          12                 4    66.67%         106                66    37.74%          40                26    35.00%
Flash/Mpp/MPPTunnelSet.h                                   4                 0   100.00%           4                 0   100.00%           6                 0   100.00%           0                 0         -
Flash/Mpp/TrackedMppDataPacket.h                          40                 9    77.50%          25                 6    76.00%         106                29    72.64%          14                 4    71.43%
Flash/Mpp/tests/gtest_mpptunnel.cpp                      300                98    67.33%          54                 0   100.00%         490                 0   100.00%          84                64    23.81%
Interpreters/ProcessList.cpp                             144                97    32.64%          11                 6    45.45%         199               102    48.74%          98                73    25.51%
Interpreters/Settings.h                                    1                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
Interpreters/executeQuery.cpp                            204               123    39.71%          15                 8    46.67%         417               213    48.92%         122                95    22.13%
Server/FlashGrpcServerHolder.cpp                         220                71    67.73%           7                 0   100.00%         158                32    79.75%          60                28    53.33%
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                   3033              1159    61.79%         428               101    76.40%        4257              1309    69.25%        1358               738    45.66%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18533      8329             55.06%    214257  85958        59.88%

full coverage report (for internal network access only)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve memtrack to reduce OOM cases
6 participants