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

*: merge the runtime stats in time to avoid using too many memory #39394

Merged
merged 19 commits into from
Nov 29, 2022

Conversation

wshwsh12
Copy link
Contributor

@wshwsh12 wshwsh12 commented Nov 25, 2022

What problem does this PR solve?

Issue Number: close #39413

Now tidb need to record some runtime stats for each executor/cop_task and so on, and merge them after the sql finfished.
If there are many cop tasks, the memory can't gc and hold util the sql finfished. Maybe it cause OOM.

Problem Summary:

When the stats will not updated, merge it to the summary stats.

What is changed and how it works?

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

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

None

@wshwsh12 wshwsh12 requested a review from a team as a code owner November 25, 2022 06:40
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Nov 25, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • XuHuaiyu
  • crazycs520

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 the release-note-none Denotes a PR that doesn't merit a release note. label Nov 25, 2022
@wshwsh12
Copy link
Contributor Author

/hold

@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Nov 25, 2022
@wshwsh12
Copy link
Contributor Author

/run-unit-test

@wshwsh12
Copy link
Contributor Author

/unhold

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 28, 2022
@@ -456,6 +454,9 @@ func (r *selectResult) Close() error {
if respSize > 0 {
r.memConsume(-respSize)
}
if r.stats != nil {
defer r.ctx.GetSessionVars().StmtCtx.RuntimeStatsColl.RegisterStats(r.rootPlanID, r.stats)
Copy link
Contributor

Choose a reason for hiding this comment

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

why use defer here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use defer to ensure that the Close()(make sure all goroutines have been exit in some parallel executer) is finished before registering stats.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-triage-completed needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. and removed do-not-merge/needs-triage-completed labels Nov 28, 2022
@XuHuaiyu XuHuaiyu changed the title *: merge the runtime stats in time to avoid using too many memroy *: merge the runtime stats in time to avoid using too many memory Nov 28, 2022
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 28, 2022
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 29, 2022
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Nov 29, 2022
@hawkingrei
Copy link
Member

@wshwsh12

    execdetails_test.go:228: 
        	Error Trace:	/home/jenkins/.tidb/tmp/63a9840cd0739f2c243bb46478607469/sandbox/linux-sandbox/3543/execroot/__main__/bazel-out/k8-fastbuild/bin/util/execdetails/execdetails_test_/execdetails_test.runfiles/__main__/util/execdetails/execdetails_test.go:228
        	Error:      	Not equal: 
        	            	expected: "tiflash_task:{proc max:2ns, min:1ns, avg: 1ns, p80:2ns, p95:2ns, iters:3, tasks:2, threads:2}, tiflash_scan:{dmfile:{total_scanned_packs:1, total_skipped_packs:0, total_scanned_rows:8192, total_skipped_rows:0, total_rough_set_index_load_time: 15ms, total_read_time: 202ms}, total_create_snapshot_time: 40ms}"
        	            	actual  : "tiflash_task:{proc max:2ns, min:1ns, avg: 1ns, p80:2ns, p95:2ns, iters:3, tasks:2, threads:2}"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-tiflash_task:{proc max:2ns, min:1ns, avg: 1ns, p80:2ns, p95:2ns, iters:3, tasks:2, threads:2}, tiflash_scan:{dmfile:{total_scanned_packs:1, total_skipped_packs:0, total_scanned_rows:8192, total_skipped_rows:0, total_rough_set_index_load_time: 15ms, total_read_time: 202ms}, total_create_snapshot_time: 40ms}
        	            	+tiflash_task:{proc max:2ns, min:1ns, avg: 1ns, p80:2ns, p95:2ns, iters:3, tasks:2, threads:2}
        	Test:       	TestCopRuntimeStatsForTiFlash

@wshwsh12
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 35bbb14

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

/run-check_dev_2

@wshwsh12
Copy link
Contributor Author

/run-all-tests

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #39462.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Nov 29, 2022
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #39463.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Nov 29, 2022
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #39464.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Nov 29, 2022
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@sre-bot
Copy link
Contributor

sre-bot commented Nov 29, 2022

TiDB MergeCI notify

✅ Well Done! New fixed [2] after this pr merged.

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/sqllogic-test-2 ✅ all 28 tests passed 6 min 13 sec Fixed
idc-jenkins-ci-tidb/integration-ddl-test ✅ all 6 tests passed 5 min 43 sec Fixed
idc-jenkins-ci/integration-cdc-test 🟢 all 40 tests passed 19 min Existing passed
idc-jenkins-ci-tidb/integration-common-test 🟢 all 17 tests passed 17 min Existing passed
idc-jenkins-ci-tidb/common-test 🟢 all 11 tests passed 10 min Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 6 min 13 sec Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 6 min 4 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 4 min 33 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 3 min 11 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. 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. 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.

Runtime info cause OOM when the cop task num is large
6 participants