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

util: optimize the memory usage of the read path for listInDisk #34778

Merged
merged 7 commits into from
Jun 6, 2022

Conversation

wshwsh12
Copy link
Contributor

@wshwsh12 wshwsh12 commented May 18, 2022

What problem does this PR solve?

Issue Number: ref #33877
close #35631
Problem Summary:

Optimize the memory usage of the read path for list in disk.

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    Workload: A big table with 5kw lines 1, a small table with 1 lines 1.
    SQL: desc analyze select * from small_table where exists (select a from v5kw big_table where small_table.b=big_table.b);
    Plan: With memory quota 1GB
[email protected]:test_xhy> desc    select * from small_table where exists (select a from v5kw big_table where small_table.b=big_table.b);
+----------------------------------+-------------+-----------+-------------------+----------------------------------------------------------------------+
| id                               | estRows     | task      | access object     | operator info                                                        |
+----------------------------------+-------------+-----------+-------------------+----------------------------------------------------------------------+
| HashJoin_15                      | 0.80        | root      |                   | semi join, equal:[eq(test_xhy.small_table.b, test_xhy.base_table.b)] |
| ├─Selection_19(Build)            | 40000000.00 | root      |                   | not(isnull(test_xhy.base_table.b))                                   |
| │ └─Limit_20                     | 50000000.00 | root      |                   | offset:0, count:50000000                                             |
| │   └─TableReader_24             | 50000000.00 | root      |                   | data:Limit_23                                                        |
| │     └─Limit_23                 | 50000000.00 | cop[tikv] |                   | offset:0, count:50000000                                             |
| │       └─TableFullScan_22       | 50000000.00 | cop[tikv] | table:base_table  | keep order:false                                                     |
| └─TableReader_18(Probe)          | 1.00        | root      |                   | data:Selection_17                                                    |
|   └─Selection_17                 | 1.00        | cop[tikv] |                   | not(isnull(test_xhy.small_table.b))                                  |
|     └─TableFullScan_16           | 1.00        | cop[tikv] | table:small_table | keep order:false, stats:pseudo                                       |
+----------------------------------+-------------+-----------+-------------------+----------------------------------------------------------------------+
9 rows in set (0.00 sec)

Before this pr: TiDB use 60GB+ and OOM.
After this pr: We can see the GC line is 5.6GB, so the memory usage after each GC is 2.8GB
image

  • 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

@ti-chi-bot
Copy link
Member

ti-chi-bot commented May 18, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • XuHuaiyu
  • guo-shaoge

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 release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 18, 2022
@sre-bot
Copy link
Contributor

sre-bot commented May 18, 2022

@@ -39,6 +39,8 @@ type ListInDisk struct {

dataFile diskFileReaderWriter
offsetFile diskFileReaderWriter

chk *Chunk
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment for this attribute.

@wshwsh12 wshwsh12 requested a review from XuHuaiyu May 18, 2022 08:34
@wshwsh12 wshwsh12 changed the title util: optimize the memory usage of the read path for listInDIsk util: optimize the memory usage of the read path for listInDisk May 18, 2022
@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 23, 2022
chk := &Chunk{columns: make([]*Column, 0, len(format.sizesOfColumns))}
// toRow deserializes diskFormatRow to Row.
func (format *diskFormatRow) toRow(fields []*types.FieldType, chk *Chunk) (Row, *Chunk) {
if chk == nil || chk.IsFull() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a quesction, chk == nil maybe unnecessary? Because sync.Pool will always new a chunk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check chk==nil is more safe.. For example, the code in test cases doesn't have the sync.Pool and doesn't need to reuse.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 23, 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 Jun 6, 2022
@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Jun 6, 2022

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 821f656

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jun 6, 2022
@ti-chi-bot
Copy link
Member

@wshwsh12: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

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 ti-community-infra/tichi repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 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.

Optimize the memory usage of the read path in hashRowContainer
5 participants