Skip to content

[vectorized](improving) (exec) optimize VDataStreamSender's send() performance #7747 - #7751

Merged
HappenLee merged 5 commits into
apache:vectorizedfrom
zuochunwei:VDataStreamSender
Jan 17, 2022
Merged

HappenLee merged 5 commits into
apache:vectorizedfrom
zuochunwei:VDataStreamSender

Conversation

@zuochunwei

Copy link
Copy Markdown
Contributor

Proposed changes

gather channel's rows, and then send together
handle each column's different rows at a time is good for improving cache hit
comparing test data, wait @zenoyang to provide

Issue Number: close #xxx

Problem Summary:

Describe the overview of changes.

Checklist(Required)

  1. Does it affect the original behavior: (Yes/No/I Don't know)
  2. Has unit tests been added: (Yes/No/No Need)
  3. Has document been added or modified: (Yes/No/No Need)
  4. Does it need to update dependencies: (Yes/No)
  5. Are there any changes that cannot be rolled back: (Yes/No)

Further comments

If this is a relatively large or complex change, kick off the discussion at [email protected] by explaining why you chose the solution you did and what alternatives you considered, etc...

Comment thread be/src/vec/core/block.cpp Outdated
auto& dst = _columns[i];
auto& src = *src_columns_with_schema[i].column.get();
for (const int* row = row_begin; row != row_end; ++row) {
dst->insert_from(src, *row);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

here will be virtual function call. so we should implement a function in column.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, that 's what i will todo next

@zenoyang

Copy link
Copy Markdown
Member
before PR (s) after PR (s)
Q2.1 4.22、4.15、4.55 4.28、4.21、4.18
Q3.1 3.99、3.88、4.14 4.00、4.04、4.12

Since DataStreamSender is fast, the complete query time may not reflect the PR difference.

@zuochunwei

Copy link
Copy Markdown
Contributor Author

before PR (s) after PR (s)
Q2.1 4.22、4.15、4.55 4.28、4.21、4.18
Q3.1 3.99、3.88、4.14 4.00、4.04、4.12
Since DataStreamSender is fast, the complete query time may not reflect the PR difference.

please test for the recently commit, thanks!

@zenoyang

Copy link
Copy Markdown
Member

new test:

before PR (s) after PR (s)
Q2.1 4.22、4.15、4.55 4.26、4.23、4.51
Q3.1 3.99、3.88、4.14 3.93、3.90、3.70

note: hash join

@zenoyang

Copy link
Copy Markdown
Member

test sql: select count(distinct lo_partkey) from lineorder

before pr

Total: 15s147ms

VDataStreamSender (dst_id=3, dst_fragments=[{"0297b49f50144c67-8175137460f3732a", "0297b49f50144c67-8175137460f3732b", "0297b49f50144c67-8175137460f3732c"}]):(Active: 13s155ms, % non-child: 86.86%)
VDataStreamSender (dst_id=3, dst_fragments=[{"0297b49f50144c67-8175137460f3732a", "0297b49f50144c67-8175137460f3732b", "0297b49f50144c67-8175137460f3732c"}]):(Active: 13s87ms, % non-child: 86.41%)
VDataStreamSender (dst_id=3, dst_fragments=[{"0297b49f50144c67-8175137460f3732a", "0297b49f50144c67-8175137460f3732b", "0297b49f50144c67-8175137460f3732c"}]):(Active: 12s833ms, % non-child: 84.73%)

VDataStreamSender cost: 
13155*0.8686=11426.433 ms
13870*0.8641=11985.067 ms
12883*0.8473=10915.766 ms

after pr

Total: 13s414ms

VDataStreamSender (dst_id=3, dst_fragments=[{"f191f98c5e644df6-a05e405fde783be2", "f191f98c5e644df6-a05e405fde783be3", "f191f98c5e644df6-a05e405fde783be4"}]):(Active: 11s129ms, % non-child: 82.97%)
VDataStreamSender (dst_id=3, dst_fragments=[{"f191f98c5e644df6-a05e405fde783be2", "f191f98c5e644df6-a05e405fde783be3", "f191f98c5e644df6-a05e405fde783be4"}]):(Active: 10s322ms, % non-child: 76.95%)
VDataStreamSender (dst_id=3, dst_fragments=[{"f191f98c5e644df6-a05e405fde783be2", "f191f98c5e644df6-a05e405fde783be3", "f191f98c5e644df6-a05e405fde783be4"}]):(Active: 9s120ms, % non-child: 67.99%)

VDataStreamSender cost: 
11129*0.8297=9233.731 ms
10322*0.7695=7942.779 ms
9120*0.6799=6200.688 ms

Comment thread be/src/vec/columns/column_decimal.h Outdated

void insert_indices_from(const IColumn& src, const int* indices_begin, const int* indices_end) override {
for (auto x = indices_begin; x != indices_end; ++x) {
Self::insert_from(src, *x);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same to the column_vector

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok


template <typename T>
void ColumnVector<T>::insert_indices_from(const IColumn& src, const int* indices_begin, const int* indices_end) {
const Self& src_vec = assert_cast<const Self&>(src);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use push_back_without_reserve

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment thread be/src/vec/columns/column_nullable.cpp Outdated
}

void ColumnNullable::insert_indices_from(const IColumn& src, const int* indices_begin, const int* indices_end) {
for (auto x = indices_begin; x != indices_end; ++x) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

which will cause to many virtural function call, refactor it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

}

// channel2rows' subscript means channel id
std::vector<vectorized::UInt64> hash_vals(rows);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should reuse the mem

// vectorized caculate hash val
int rows = block->rows();
// for each row, we have a hash_val
std::vector<size_t> hash_vals(rows);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should reuse the mem


template <typename Channels, typename HashVals>
Status VDataStreamSender::channel_add_rows(Channels& channels, int num_channels, const HashVals& hash_vals, int rows, Block* block) {
std::vector<int> channel2rows[num_channels];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same to the up, we should reuse the mem

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

channel2rows is used for aggregate rows for channels, it's a temporary data served for the function of channel_add_rows, it's not used in other member functions, it's not has getter/setter, it's not visiable to outer, so i don't think make it as member data is a good idea.

for performance, if you can prove it with rewriting code, please tell me

@HappenLee
HappenLee merged commit 778fa8d into apache:vectorized Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants