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

Fine grained partition writer optimization #6173

Merged
merged 29 commits into from
Oct 31, 2022

Conversation

yibin87
Copy link
Contributor

@yibin87 yibin87 commented Oct 20, 2022

What problem does this PR solve?

Issue Number: ref #6157

Problem Summary:

  1. Current FineGrainedShuffleWriter allocates new memory for scattered columns each time when batchWrite is triggered.
  2. "Long tail problem", cached blocks under thres won't write until readSuffix, which's executed in a single thread.

This PR aims to reuse memory for scattered columns and "Long tail problem".
Referenced PR: #3787

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

None

Signed-off-by: yibin <huyibin@pingcap.com>
Signed-off-by: yibin <huyibin@pingcap.com>
Signed-off-by: yibin <huyibin@pingcap.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Oct 20, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • SeaRise
  • 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 20, 2022
Signed-off-by: yibin <huyibin@pingcap.com>
@ti-chi-bot ti-chi-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 20, 2022
Signed-off-by: yibin <huyibin@pingcap.com>
Signed-off-by: yibin <huyibin@pingcap.com>
Signed-off-by: yibin <huyibin@pingcap.com>
@SeaRise SeaRise self-requested a review October 20, 2022 10:40
Signed-off-by: yibin <huyibin@pingcap.com>
Signed-off-by: yibin <huyibin@pingcap.com>
Signed-off-by: yibin <huyibin@pingcap.com>
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 28, 2022
@yibin87 yibin87 requested a review from SeaRise October 28, 2022 02:17
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 28, 2022
@yibin87
Copy link
Contributor Author

yibin87 commented Oct 28, 2022

/run-unit-tests

@yibin87
Copy link
Contributor Author

yibin87 commented Oct 31, 2022

/run-unit-tests

Copy link
Contributor

@SeaRise SeaRise left a comment

Choose a reason for hiding this comment

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

LGTM

dbms/src/Columns/tests/gtest_column_scatterTo.cpp Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Oct 31, 2022
size_t rows = block.rows();
rows_in_blocks += rows;
if (rows > 0)
{
blocks.push_back(block);
}

if (static_cast<UInt64>(rows_in_blocks) >= fine_grained_shuffle_batch_size)
if (blocks.size() == fine_grained_shuffle_stream_count || static_cast<UInt64>(rows_in_blocks) >= batch_send_row_limit)
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. So we changed the meaning of fine_grained_shuffle_batch_size, maybe need to talk to PM and also change the doc
  2. Just a question: why trigger sending data when blocks.size() equals to fine_grained_shuffle_stream_count

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion and question. For 1, I'll follow. For 2, just think like this:
Previously, no fine_grained_shuffle_stream, N partitions, then one block => N blocks
With fine_grained_shuffle_stream, N partitions, M fine_grained_shuffle_stream_count, then one block => N * M blocks, thus here use blocks.size() == stream_count, can make final block close to previous block size.

Copy link
Contributor

@guo-shaoge guo-shaoge Oct 31, 2022

Choose a reason for hiding this comment

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

Got it. So compared to the original situation, will trigger batchWrite more frequent when blocks are small. Guess this is the reason why long tail problem can be fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Long tail problem is actually fixed by the "flush" interface, which will be invoked concurrently in different threads. Previously, the remain cached blocks that are below thres, will be flushed in "finishWrite" interface, which is invoked sequentially in a single thread.

yibin87 and others added 4 commits October 31, 2022 10:46
Co-authored-by: SeaRise <hhssearise@foxmail.com>
Co-authored-by: SeaRise <hhssearise@foxmail.com>
Signed-off-by: yibin <huyibin@pingcap.com>
Signed-off-by: yibin <huyibin@pingcap.com>
@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 Oct 31, 2022
{
/// Materialize sample_block so that header and reserved scatterColumns are full columns
/// Because ser/der don't support constant columns now
header = sample_block.cloneEmpty();
Copy link
Contributor

Choose a reason for hiding this comment

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

The column in ColumnWithTypeAndName can be nullptr sometimes, so I'm a little warried that HashBaseWriterHelper::materializeBlock may meet a npe problem, how about creating the scatter columns use the type in ColumnWithTypeAndName?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// fine_grained_shuffle_stream_count is in (0, 1024], and partition_num is uint16_t, so will not overflow.
num_bucket = partition_num * fine_grained_shuffle_stream_count;
partition_key_containers_for_reuse.resize(collators.size());
resetScatterColumns();
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like resetScatterColumns is only used in prepare, it's more like initScatterColumns?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to initScatterColumns

Signed-off-by: yibin <huyibin@pingcap.com>
Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

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

LGTM

@yibin87
Copy link
Contributor Author

yibin87 commented Oct 31, 2022

/merge

@ti-chi-bot
Copy link
Member

@yibin87: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and 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.

If you have any questions about the PR merge process, please refer to pr process.

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.

@ti-chi-bot
Copy link
Member

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

Commit hash: 6ef1faf

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

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

@ti-chi-bot ti-chi-bot merged commit c73daf6 into pingcap:master Oct 31, 2022
CalvinNeo pushed a commit to CalvinNeo/tiflash that referenced this pull request Nov 4, 2022
close pingcap#6157

Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
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/XXL Denotes a PR that changes 1000+ 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.

5 participants