Created
July 16, 2019 07:09
-
-
Save toddlipcon/e00c7f8e8360cd663d2ab1ac48959c9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 9bf51d73c66e36c5f5d26eb161683507d5717069 (HEAD) | |
Author: Todd Lipcon <todd@apache.org> | |
Date: Mon Jul 15 23:52:10 2019 -0700 | |
wip: wire protocol opt | |
Change-Id: I118b01ae2acfd8dd290e7f67445796635d305351 | |
diff --git a/src/kudu/common/wire_protocol-test.cc b/src/kudu/common/wire_protocol-test.cc | |
index 0317cab47..68e22bdc8 100644 | |
--- a/src/kudu/common/wire_protocol-test.cc | |
+++ b/src/kudu/common/wire_protocol-test.cc | |
@@ -151,22 +151,28 @@ class WireProtocolTest : public KuduTest, | |
void RunBenchmark(int column_count, double select_rate) { | |
ResetBenchmarkSchema(column_count); | |
Arena arena(1024); | |
- const int kNumTrials = AllowSlowTests() ? 100 : 10; | |
- RowBlock block(&benchmark_schema_, 10000, &arena); | |
+ RowBlock block(&benchmark_schema_, 1000, &arena); | |
+ // Regardless of the config, use a constant number of cells for the test by | |
+ // looping the conversion an appropriate number of times. | |
+ const int64_t kNumCellsToConvert = AllowSlowTests() ? 100000000 : 1000000; | |
+ const int kNumTrials = kNumCellsToConvert / select_rate / column_count / block.nrows(); | |
FillRowBlockForBenchmark(&block); | |
SelectRandomRowsWithRate(&block, select_rate); | |
RowwiseRowBlockPB pb; | |
faststring direct, indirect; | |
- LOG_TIMING(INFO, Substitute("Converting to PB with column count $0 and row select rate $1 ", | |
- column_count, select_rate)) { | |
- for (int i = 0; i < kNumTrials; ++i) { | |
- pb.Clear(); | |
- direct.clear(); | |
- indirect.clear(); | |
- SerializeRowBlock(block, &pb, nullptr, &direct, &indirect); | |
- } | |
+ int64_t cycle_start = CycleClock::Now(); | |
+ for (int i = 0; i < kNumTrials; ++i) { | |
+ pb.Clear(); | |
+ direct.clear(); | |
+ indirect.clear(); | |
+ SerializeRowBlock(block, &pb, nullptr, &direct, &indirect); | |
} | |
+ int64_t cycle_end = CycleClock::Now(); | |
+ LOG(INFO) << Substitute( | |
+ "Converting to PB with column count $0 and row select rate $1: $2 cycles/cell", | |
+ column_count, select_rate, | |
+ static_cast<double>(cycle_end - cycle_start) / kNumCellsToConvert); | |
} | |
protected: | |
Schema schema_; | |
diff --git a/src/kudu/common/wire_protocol.cc b/src/kudu/common/wire_protocol.cc | |
index 30de63f93..3a6be2b00 100644 | |
--- a/src/kudu/common/wire_protocol.cc | |
+++ b/src/kudu/common/wire_protocol.cc | |
@@ -892,7 +892,7 @@ void AppendRowToString<RowBlockRow>(const RowBlockRow& row, string* buf) { | |
// be copied to column 'dst_col_idx' in the output protobuf; otherwise, | |
// dst_col_idx must be equal to col_idx. | |
template<bool IS_NULLABLE, bool IS_VARLEN> | |
-static void CopyColumn(const ColumnBlock& column_block, int dst_col_idx, uint8_t* dst_base, | |
+static void CopyColumn(const ColumnBlock& column_block, int dst_col_idx, uint8_t* __restrict__ dst_base, | |
faststring* indirect_data, const Schema* dst_schema, size_t row_stride, | |
size_t schema_byte_size, size_t column_offset, | |
const vector<int>& row_idx_select) { | |
@@ -930,25 +930,28 @@ static void CopyColumn(const ColumnBlock& column_block, int dst_col_idx, uint8_t | |
void convert_bitmap_to_vector(const SelectionVector* sel_vec, size_t nrows, | |
vector<int>* select_row_idx) { | |
- int row_idx = 0; | |
- int run_size = 0; | |
- bool selected = false; | |
- if (!sel_vec->AnySelected()) { | |
+ | |
+ int n_selected = sel_vec->CountSelected(); | |
+ if (n_selected == 0) { | |
return; | |
} | |
- if (sel_vec->CountSelected() == nrows) { | |
- select_row_idx->resize(nrows); | |
+ select_row_idx->resize(n_selected); | |
+ int row_idx = 0; | |
+ if (n_selected == nrows) { | |
std::iota(select_row_idx->begin(), select_row_idx->end(), row_idx); | |
return; | |
} | |
- BitmapIterator selected_row_iter(sel_vec->bitmap(), nrows); | |
- while ((run_size = selected_row_iter.Next(&selected))) { | |
- if (selected) { | |
- select_row_idx->resize(select_row_idx->size() + run_size); | |
- std::iota(select_row_idx->end() - run_size, select_row_idx->end(), row_idx); | |
+ int n_bytes = KUDU_ALIGN_UP(nrows, 8) / 8; | |
+ const uint8_t* bitmap = sel_vec->bitmap(); | |
+ int* dst = select_row_idx->data(); | |
+ for (int i = 0; i < n_bytes; i++) { | |
+ uint8_t bm = *bitmap++; | |
+ while (bm != 0) { | |
+ int bit = Bits::FindLSBSetNonZero(bm); | |
+ *dst++ = (i * 8) + bit; | |
+ bm ^= (1 << bit); | |
} | |
- row_idx += run_size; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment