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

*: some tiny optimizations to reduce infoschema v2 memory #53242

Merged
merged 4 commits into from
May 14, 2024

Conversation

tiancaiamao
Copy link
Contributor

@tiancaiamao tiancaiamao commented May 14, 2024

What problem does this PR solve?

Issue Number: ref #50959

Problem Summary:

What changed and how does it work?

  1. Change some calling from SchemaTables() to SchemaTableInfos()

SchemaTables() is heavier than SchemaTableInfos() because the former need to load model.TableInfo from meta kv first and then build table.Table from model.TableInfo

The caller only need the model.TableInfo, so change them to SchemaTableInfos.

  1. Reset Tables field of model.DBInfo when adding it to infoschema v2

I found some leaky memory occupation in infoschema v2:
image23

It turn out to be that the model.DBInfo reference the Tables, so the memoy of json data can not be freed.

  1. Skip refill cache In SchemaTables()

Fill cache in the list API cause the memory thrash and also CPU thrash.
Especally I find the cost of Sizeof() is much higher than estimated.
When we add to cache or evict cache, we need to call Sizeof() to calculate the size of an object.
Skip refill cache in SchemaTables() can avoid much of that.

Check List

Tests

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

I create a lot of partition tables and watch the memory usage.
The first issue is co-exist of infoschema v1 and v2, cause the memory usage doubled.
We can workaround it by setting DefTiDBSchemaCacheSize > 0 rather than setting @@global.tidb_schema_cache_size. (not done in this pull request)

image15

The second to third red square in the picture above shows the effect of this pull request.

  • 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

@tiancaiamao tiancaiamao requested a review from GMHDBJD May 14, 2024 02:12
@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 May 14, 2024
Copy link

tiprow bot commented May 14, 2024

Hi @tiancaiamao. 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.

@tiancaiamao tiancaiamao requested a review from ywqzzy May 14, 2024 02:36
Copy link

codecov bot commented May 14, 2024

Codecov Report

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

Project coverage is 74.5301%. Comparing base (37b29bd) to head (93ac090).
Report is 7 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #53242        +/-   ##
================================================
+ Coverage   72.4582%   74.5301%   +2.0719%     
================================================
  Files          1493       1493                
  Lines        429362     429696       +334     
================================================
+ Hits         311108     320253      +9145     
+ Misses        98985      89537      -9448     
- Partials      19269      19906       +637     
Flag Coverage Δ
integration 49.0289% <64.2857%> (?)
unit 71.2582% <80.9523%> (-0.0982%) ⬇️

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

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

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label May 14, 2024
@tiancaiamao
Copy link
Contributor Author

/retest-required

Copy link

tiprow bot commented May 14, 2024

@tiancaiamao: 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.

Copy link

ti-chi-bot bot commented May 14, 2024

[APPROVALNOTIFIER] This PR is APPROVED

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

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 approved lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels May 14, 2024
Copy link

ti-chi-bot bot commented May 14, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-05-14 06:32:14.314562188 +0000 UTC m=+1548488.071697763: ☑️ agreed by ywqzzy.
  • 2024-05-14 08:24:45.319432574 +0000 UTC m=+1555239.076568151: ☑️ agreed by hawkingrei.

@hawkingrei
Copy link
Member

/retest

@ti-chi-bot ti-chi-bot bot merged commit be80474 into pingcap:master May 14, 2024
23 checks passed
@tiancaiamao tiancaiamao deleted the infoschema-mem branch May 14, 2024 11:57
terry1purcell pushed a commit to terry1purcell/tidb that referenced this pull request May 17, 2024
RidRisR pushed a commit to RidRisR/tidb that referenced this pull request May 23, 2024
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.

3 participants