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

planner: optimize performance of IndexUsage utilities #53195

Merged

Conversation

YangKeao
Copy link
Member

@YangKeao YangKeao commented May 11, 2024

What problem does this PR solve?

Issue Number: close #51898

Problem Summary:

This PR is trying to optimize the performance of IndexUsage utilities. Previously it costed around 1% CPU and did a lot of allocation. This PR tries to optimize it and get some tiny performance boost.

What changed and how does it work?

  1. Add a pool to avoid frequently allocating/de-allocating indexUsage and the internal entries.
  2. Avoid using getTblInfoForUsedStatsByPhysicalID, which is very slow because it iterates over all tables.

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.

I used https://gist.github.com/YangKeao/c02ada99d2602d5e7fb5fb94f0581015 to run a stabler select_random_points benchmark. It gives QPS 59029 and 58393 for the commit before index usage and with index usage enabled.

After patching the index usage commit with this PR, the average QPS goes to 58854. I'm not sure whether there are other spaces to improve the performance (like improving the speed of loading stats).

As a reference: the flamegraph before this PR:

Screenshot_20240511_135754

The flamegraph after this PR:

Screenshot_20240511_172151

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

Copy link

ti-chi-bot bot commented May 11, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-tests-checked do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none sig/planner SIG: Planner labels May 11, 2024
Copy link

tiprow bot commented May 11, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 11, 2024
@YangKeao YangKeao force-pushed the optimize-index-usage-performance branch from 8940205 to 8b925b9 Compare May 11, 2024 09:24
@YangKeao YangKeao marked this pull request as ready for review May 11, 2024 09:25
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 11, 2024
@YangKeao YangKeao changed the title DNM, planner: optimize performance of IndexUsage utilities planner: optimize performance of IndexUsage utilities May 11, 2024
@YangKeao YangKeao force-pushed the optimize-index-usage-performance branch from 8b925b9 to 2c43f8b Compare May 11, 2024 09:30
Signed-off-by: Yang Keao <yangkeao@chunibyo.icu>
@YangKeao YangKeao force-pushed the optimize-index-usage-performance branch from 2c43f8b to 01c0eb3 Compare May 11, 2024 09:38
Copy link

codecov bot commented May 11, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 74.4752%. Comparing base (9831208) to head (01c0eb3).
Report is 12 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #53195        +/-   ##
================================================
+ Coverage   72.4647%   74.4752%   +2.0105%     
================================================
  Files          1492       1492                
  Lines        429133     431318      +2185     
================================================
+ Hits         310970     321225     +10255     
+ Misses        98950      90176      -8774     
- Partials      19213      19917       +704     
Flag Coverage Δ
integration 49.0293% <71.8750%> (?)
unit 71.2371% <75.0000%> (-0.1203%) ⬇️

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

Components Coverage Δ
dumpling 53.9957% <ø> (ø)
parser ∅ <ø> (∅)
br 50.2007% <ø> (+8.7605%) ⬆️

@hawkingrei
Copy link
Member

/retest

Copy link

ti-chi-bot bot commented May 13, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hawkingrei, qw4990

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

Copy link

ti-chi-bot bot commented May 13, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-05-13 01:05:15.979633972 +0000 UTC m=+1442469.736769544: ☑️ agreed by hawkingrei.
  • 2024-05-13 04:00:03.80272207 +0000 UTC m=+1452957.559857644: ☑️ agreed by qw4990.

@ti-chi-bot ti-chi-bot bot merged commit e5651c4 into pingcap:master May 13, 2024
22 of 23 checks passed
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.0: #53214.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #53215.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

There is a 2%-4% performance regression in sysbench select_random_points
4 participants