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

domain: Optimize GetDomain api #58550

Merged
merged 7 commits into from
Dec 28, 2024

Conversation

crazycs520
Copy link
Contributor

@crazycs520 crazycs520 commented Dec 26, 2024

What problem does this PR solve?

Issue Number: ref #56649

Problem Summary:

What changed and how does it work?

Before this PR: GetDomain cost 0.96%

▶ go tool pprof cpu_tidb_10.202.0.23_4000_508736934.proto
File: tidb-server
Build ID: 8f92f680e128d31d0abcc371d89a91928179505c
Type: cpu
Time: Dec 26, 2024 at 4:53pm (CST)
Duration: 29.28s, Total samples = 365.82s (1249.44%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) peek GetDomain
Showing nodes accounting for 365.82s, 100% of 365.82s total
----------------------------------------------------------+-------------
      flat  flat%   sum%        cum   cum%   calls calls% + context
----------------------------------------------------------+-------------
                                             0.55s 28.21% |   github.com/pingcap/tidb/pkg/executor.checkPlanReplayerCaptureTask (inline)
                                             0.47s 24.10% |   github.com/pingcap/tidb/pkg/session.(*session).GetDomainInfoSchema (inline)
                                             0.28s 14.36% |   github.com/pingcap/tidb/pkg/planner/core.getStatsTable (inline)
                                             0.15s  7.69% |   github.com/pingcap/tidb/pkg/planner.init.0.func1 (inline)
                                             0.15s  7.69% |   github.com/pingcap/tidb/pkg/planner/core.planCachePreprocess (inline)
                                             0.13s  6.67% |   github.com/pingcap/tidb/pkg/session.(*session).ExecuteStmt (inline)
                                             0.12s  6.15% |   github.com/pingcap/tidb/pkg/executor.ResetContextOfStmt (inline)
                                             0.10s  5.13% |   github.com/pingcap/tidb/pkg/planner/core.getLatestVersionFromStatsTable (inline)
     0.34s 0.093% 0.093%      1.95s  0.53%                | github.com/pingcap/tidb/pkg/domain.GetDomain
                                             1.61s 82.56% |   github.com/pingcap/tidb/pkg/session.(*session).Value
----------------------------------------------------------+-------------
                                             1.56s   100% |   github.com/pingcap/tidb/pkg/sessiontxn/isolation.(*baseTxnContextProvider).OnInitialize
     0.17s 0.046%  0.14%      1.56s  0.43%                | github.com/pingcap/tidb/pkg/session.(*session).GetDomainInfoSchema
                                             0.47s 30.13% |   github.com/pingcap/tidb/pkg/domain.GetDomain (inline)
                                             0.44s 28.21% |   github.com/pingcap/tidb/pkg/domain.(*Domain).InfoSchema (inline)
                                             0.33s 21.15% |   runtime.newobject
                                             0.15s  9.62% |   github.com/pingcap/tidb/pkg/table/temptable.AttachLocalTemporaryTableInfoSchema
----------------------------------------------------------+-------------

This PR: GetDomain cost 0.57%

▶ go tool pprof cpu_tidb_10.202.0.23_4000_3538456240.proto
File: tidb-server
Build ID: 0bee02b4eee34452eb21d71478d92a322654c36d
Type: cpu
Time: Dec 26, 2024 at 5:42pm (CST)
Duration: 29.24s, Total samples = 365.85s (1251.07%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof)
(pprof) peek GetDomain
Showing nodes accounting for 365.85s, 100% of 365.85s total
----------------------------------------------------------+-------------
      flat  flat%   sum%        cum   cum%   calls calls% + context
----------------------------------------------------------+-------------
                                             0.12s 20.69% |   github.com/pingcap/tidb/pkg/executor.checkPlanReplayerCaptureTask (inline)
                                             0.11s 18.97% |   github.com/pingcap/tidb/pkg/planner/core.getStatsTable (inline)
                                             0.10s 17.24% |   github.com/pingcap/tidb/pkg/session.(*session).GetDomainInfoSchema (inline)
                                             0.09s 15.52% |   github.com/pingcap/tidb/pkg/executor.ResetContextOfStmt (inline)
                                             0.07s 12.07% |   github.com/pingcap/tidb/pkg/planner/core.planCachePreprocess (inline)
                                             0.05s  8.62% |   github.com/pingcap/tidb/pkg/planner/core.getLatestVersionFromStatsTable (inline)
                                             0.04s  6.90% |   github.com/pingcap/tidb/pkg/planner.init.0.func1 (inline)
     0.33s  0.09%  0.09%      0.58s  0.16%                | github.com/pingcap/tidb/pkg/domain.GetDomain
                                             0.25s 43.10% |   github.com/pingcap/tidb/pkg/session.(*session).GetDomain
----------------------------------------------------------+-------------
                                             0.25s   100% |   github.com/pingcap/tidb/pkg/domain.GetDomain
     0.25s 0.068%  0.16%      0.25s 0.068%                | github.com/pingcap/tidb/pkg/session.(*session).GetDomain
----------------------------------------------------------+-------------
                                             1.24s   100% |   github.com/pingcap/tidb/pkg/sessiontxn/isolation.(*baseTxnContextProvider).OnInitialize
     0.21s 0.057%  0.22%      1.24s  0.34%                | github.com/pingcap/tidb/pkg/session.(*session).GetDomainInfoSchema
                                             0.43s 34.68% |   github.com/pingcap/tidb/pkg/domain.(*Domain).InfoSchema (inline)
                                             0.31s 25.00% |   runtime.newobject
                                             0.19s 15.32% |   github.com/pingcap/tidb/pkg/table/temptable.AttachLocalTemporaryTableInfoSchema
                                             0.10s  8.06% |   github.com/pingcap/tidb/pkg/domain.GetDomain (inline)
----------------------------------------------------------+-------------
version workload thread QPS QPS Increase
master oltp_point_select 50 74171  
This PR oltp_point_select 50 74426 0.3%

Check List

Tests

  • 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.

None

Signed-off-by: crazycs520 <[email protected]>
@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 26, 2024
Copy link

tiprow bot commented Dec 26, 2024

Hi @crazycs520. 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-sigs/prow repository.

Signed-off-by: crazycs520 <[email protected]>
Signed-off-by: crazycs520 <[email protected]>
Copy link

codecov bot commented Dec 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.2689%. Comparing base (3c40731) to head (3414757).
Report is 40 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #58550        +/-   ##
================================================
+ Coverage   73.5554%   75.2689%   +1.7135%     
================================================
  Files          1680       1725        +45     
  Lines        464640     477150     +12510     
================================================
+ Hits         341768     359146     +17378     
+ Misses       102005      95774      -6231     
- Partials      20867      22230      +1363     
Flag Coverage Δ
integration 49.3095% <53.8461%> (?)
unit 72.6736% <100.0000%> (+0.3842%) ⬆️

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

Components Coverage Δ
dumpling 52.6910% <ø> (ø)
parser ∅ <ø> (∅)
br 61.6835% <ø> (+15.9090%) ⬆️

@crazycs520
Copy link
Contributor Author

/retest-required

Copy link

tiprow bot commented Dec 26, 2024

@crazycs520: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest-required

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-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 27, 2024
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 27, 2024
Copy link

ti-chi-bot bot commented Dec 27, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-12-27 03:33:54.711593439 +0000 UTC m=+62170.067597978: ☑️ agreed by zyguan.
  • 2024-12-27 06:00:20.100775344 +0000 UTC m=+70955.456779883: ☑️ agreed by tiancaiamao.

@@ -182,6 +182,7 @@ type session struct {
currentCtx context.Context // only use for runtime.trace, Please NEVER use it.
currentPlan base.Plan

dom any
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe leave a TODO to replace the usage of any in the future, it will reduce code maintainability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I add a comment here.

Copy link

ti-chi-bot bot commented Dec 28, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, tangenta, tiancaiamao, winoros, zyguan

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 ti-chi-bot bot added the approved label Dec 28, 2024
@ti-chi-bot ti-chi-bot bot merged commit cdcc291 into pingcap:master Dec 28, 2024
24 checks passed
@crazycs520 crazycs520 deleted the tiny-opt-get-domain-api branch December 29, 2024 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants