tidb icon indicating copy to clipboard operation
tidb copied to clipboard

br: support to stop gc memory limit tuner when restore

Open Leavrth opened this issue 1 year ago • 6 comments
trafficstars

What problem does this PR solve?

Issue Number: close #51078

Problem Summary: gc memory limit tuner decreases the frequency of GC triggered by memory limitation. backup/restore would downlaod/unmarshal much schema data, which creates large temporary data in memory. Therefore, BR needs to stop gc memory limit tuner.

What changed and how does it work?

add a switch to invalidate the debug.SetMemoryLimit operation in gc memory limit tuner.

Check List

Tests

  • [x] Unit test
  • [ ] Integration test
  • [ ] Manual test (add detailed scripts or steps below)
  • [ ] No need to test
    • [ ] I checked and no code files have been changed.

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

Please refer to Release Notes Language Style Guide to write a quality release note.

introduce a parameter `--memory-limit`(Byte) to set go memory limit.

Leavrth avatar Feb 09 '24 03:02 Leavrth

Hi @Leavrth. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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 kubernetes/test-infra repository.

tiprow[bot] avatar Feb 09 '24 03:02 tiprow[bot]

Codecov Report

Merging #51082 (46403b6) into master (f46bded) will increase coverage by 2.3251%. Report is 127 commits behind head on master. The diff coverage is 69.2307%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #51082        +/-   ##
================================================
+ Coverage   70.5615%   72.8867%   +2.3251%     
================================================
  Files          1467       1476         +9     
  Lines        434897     457418     +22521     
================================================
+ Hits         306870     333397     +26527     
+ Misses       108755     103650      -5105     
- Partials      19272      20371      +1099     
Flag Coverage Δ
integration 49.2622% <5.5555%> (?)
unit 70.5516% <69.2307%> (+0.1842%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 54.2644% <ø> (-0.0297%) :arrow_down:
parser ∅ <ø> (∅)
br 49.9730% <50.0000%> (+4.2012%) :arrow_up:

codecov[bot] avatar Feb 09 '24 06:02 codecov[bot]

/review default

jayl1e avatar Feb 12 '24 06:02 jayl1e

@lijie0123:

Review comments

Overall, the changes are well-structured, and it's clear what issue this pull request is trying to solve. However, there are some points that need attention:

  1. Documentation: The newly added function setMemoryLimit in memory_limit_tuner.go lacks function-level comments. Please add comments to describe its functionality and usage.

  2. Error handling: In the function DisableSetMemoryLimit, there is no error handling for the case when debug.SetMemoryLimit(limit) fails. Please handle this error appropriately.

  3. Test Coverage: The test TestSetMemoryLimit in memory_limit_tuner_test.go only tests the happy path. Please also add error cases to validate the behavior of the function when errors occur.

  4. Data Race: The counter disable in setMemoryLimitSwitch struct is not protected by a mutex for all operations. This could lead to data race issues if the EnableSetMemoryLimit and DisableSetMemoryLimit functions are called concurrently from different goroutines. Please ensure that all operations on shared data are protected by mutexes.

  5. Consistent naming: The function name DisableSetMemoryLimit suggests that it would disable setting the memory limit but it actually sets the memory limit if the limit is greater than 0. Consider renaming it to better reflect its functionality.

Suggested changes:

diff --git a/pkg/util/gctuner/memory_limit_tuner.go b/pkg/util/gctuner/memory_limit_tuner.go
index b01c6beae3da..b01c6beae3db 100644
--- a/pkg/util/gctuner/memory_limit_tuner.go
+++ b/pkg/util/gctuner/memory_limit_tuner.go
@@ -40,7 +40,7 @@ func setMemoryLimit(limit int64) int64 {
        return 0
 }
 
-// DisableSetMemoryLimit disables the memory limit tuner to set go memory limit.
+// SetMemoryLimitAndDisableTuner sets the go memory limit and disables the memory limit tuner.
 // It also set the go memory limit and return the original go memory limit if in need.
 func DisableSetMemoryLimit(limit int64) int64 {
        globalSetMemoryLimitSwitch.Lock()
@@ -60,11 +60,14 @@ func (t *memoryLimitTuner) tuning() {
                //   MemoryLimit after the **next**
......
> Response is trunked for length limits.

<details>

In response to [this](https://github.com/pingcap/tidb/pull/51082#issuecomment-1938121008):

>/review default


Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
</details>

ti-chi-bot[bot] avatar Feb 12 '24 06:02 ti-chi-bot[bot]

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wshwsh12, YuJuncen

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

ti-chi-bot[bot] avatar Feb 29 '24 07:02 ti-chi-bot[bot]

[LGTM Timeline notifier]

Timeline:

  • 2024-02-29 07:09:24.80645505 +0000 UTC m=+1118653.554078160: :ballot_box_with_check: agreed by wshwsh12.
  • 2024-02-29 07:26:35.333548155 +0000 UTC m=+1119684.081171266: :ballot_box_with_check: agreed by YuJuncen.

ti-chi-bot[bot] avatar Feb 29 '24 07:02 ti-chi-bot[bot]

@Leavrth: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
tidb_parser_test 46403b67290426619bb8f6e79483d447bf694af3 link true /test tidb_parser_test
fast_test_tiprow 46403b67290426619bb8f6e79483d447bf694af3 link true /test fast_test_tiprow

Full PR test history. Your PR dashboard.

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 kubernetes/test-infra repository. I understand the commands that are listed here.

tiprow[bot] avatar Feb 29 '24 07:02 tiprow[bot]