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

change the exchange packets interface among tiflash #3184

Merged
merged 9 commits into from
Oct 14, 2021

Conversation

fzhedu
Copy link
Contributor

@fzhedu fzhedu commented Oct 8, 2021

What problem does this PR solve?

Issue Number: close #xxx

Problem Summary:

exchange encodes blocks twice thus decodes blocks twice, i.e., block -> response -> packet , taking more CPU, to solve this issue, this PR directly serializes blocks into packets. In detail, block -> packet for the non-last packets, but for the last packet, block -> packet.chunks and execution_summaries -> response -> packet.data. This change aims to exchanging data among tiflash, sending data from tiflash to tidb as previous doing.

What is changed and how it works?

Proposal: change kvproto

What's Changed:

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch:

Check List

Tests

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

Side effects

Release note

reduce unnecessary memory copy when encoding/decoding packets for exchanging data among tiflash

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Oct 8, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • windtalker

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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 8, 2021
@ti-chi-bot ti-chi-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 8, 2021
@@ -91,4 +93,14 @@ Block CHBlockChunkCodec::decode(const tipb::Chunk & chunk, const DAGSchema & sch
return block_in.read();
}

Block CHBlockChunkCodec::decode(const std::string & str, const DAGSchema & schema)
Copy link
Contributor

Choose a reason for hiding this comment

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

L88-L93 is the same as L98-L103, should reuse them.

class CHBlockChunkCodec : public ChunkCodec
{
public:
CHBlockChunkCodec() = default;
Block decode(const tipb::Chunk &, const DAGSchema &) override;
Block decode(const std::string &, const DAGSchema &);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just change Block decode(const tipb::Chunk &, const DAGSchema &) to Block decode(const std::string &, const DAGSchema &) in the base class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated


void write(mpp::MPPDataPacket &)
{
assert(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Throw exception with unsupported error.

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

}
void write(mpp::MPPDataPacket &, [[maybe_unused]] uint16_t)
{
assert(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

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

if (records_per_chunk == -1)
{
mpp::MPPDataPacket packet;
Copy link
Contributor

Choose a reason for hiding this comment

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

TiSpark supports CHBlock encode type, will it be affected by this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

writing to tispark uses current_memory_tracker? I suppose this branch only works for shuffing among tiflash.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by writing to tispark uses current_memory_tracker? Writing to TiSpark does use StreamingDAGResponseWriter. And I think we can only guarantee that partitionAndEncodeThenWriteBlocks is used among TiFlash.


auto rows = result.decodeChunks(block_queue, remote_reader->getOutputSchema(), expected_types);
/// return empty msg after all its chunks are decoded.
remote_reader->returnEmptyMsg(&result);
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks weird to divide the fetch result into 3 part:

  1. remote_reader->nextResult
  2. result.decodeChunks
  3. remote_reader->returnEmptyMsg

I suggest to redefine remote_reader->nextResult, move the logical of Chunk => Block into nextResult, so we do not need result.decodeChunks and remote_reader->returnEmptyMsg, just call remote_reader->nextResult is enough.

@fzhedu
Copy link
Contributor Author

fzhedu commented Oct 11, 2021

/run-all-tests

@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 11, 2021
@fzhedu
Copy link
Contributor Author

fzhedu commented Oct 11, 2021

/run-all-tests

@fzhedu
Copy link
Contributor Author

fzhedu commented Oct 11, 2021

/run-all-tests

if (records_per_chunk == -1)
{
mpp::MPPDataPacket packet;
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by writing to tispark uses current_memory_tracker? Writing to TiSpark does use StreamingDAGResponseWriter. And I think we can only guarantee that partitionAndEncodeThenWriteBlocks is used among TiFlash.

void MPPTunnelSetBase<Tunnel>::write(mpp::MPPDataPacket & packet)
{
auto tunnels_size = tunnels.size();
if (tunnels_size > 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

when tunnels_size == 1, the packet is ignored?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is a bug, fixed.

responses[i] = response;
responses[i].set_encode_type(encode_type);
if constexpr (for_last_response)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

For both broadcast and partition writer, only one response needs to carry the execution summary info.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated in TunnelSet->write()

@fzhedu
Copy link
Contributor Author

fzhedu commented Oct 11, 2021

/run-all-tests

1 similar comment
@fzhedu
Copy link
Contributor Author

fzhedu commented Oct 12, 2021

/run-all-tests

@fzhedu
Copy link
Contributor Author

fzhedu commented Oct 12, 2021

/run-all-tests

1 similar comment
@fzhedu
Copy link
Contributor Author

fzhedu commented Oct 13, 2021

/run-all-tests

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.

others LGTM

block_queue.push(std::move(block));
}
}
else if (!recv_msg->packet->data().empty())
Copy link
Contributor

Choose a reason for hiding this comment

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

useless code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

responses[i].set_encode_type(encode_type);
if constexpr (for_last_response)
{
if (i == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add some comments to make it more readable.

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

@@ -1,5 +1,8 @@
#include <Common/CPUAffinityManager.h>
#include <Common/ThreadFactory.h>
#include <Flash/Coprocessor/ArrowChunkCodec.h>
#include <Flash/Coprocessor/CoprocessorReader.h>
#include <Flash/Coprocessor/DefaultChunkCodec.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

useless header file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Oct 13, 2021
@fzhedu
Copy link
Contributor Author

fzhedu commented Oct 14, 2021

/merge

@ti-chi-bot
Copy link
Member

@fzhedu: 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: f5134d8

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 14, 2021
@ti-chi-bot ti-chi-bot merged commit b7e87dd into pingcap:master Oct 14, 2021
@JaySon-Huang JaySon-Huang deleted the ReduceEncodeCopy branch January 5, 2022 13:01
@fzhedu fzhedu restored the ReduceEncodeCopy branch March 25, 2022 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants