Skip to content

Commit

Permalink
[Chore](profile) add some profile on ReaderInit (apache#45556)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?
add some profile on ReaderInit
  • Loading branch information
BiteTheDDDDt authored Dec 20, 2024
1 parent 2a1209d commit e3f3f47
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 49 deletions.
5 changes: 4 additions & 1 deletion be/src/olap/base_tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "common/status.h"
#include "olap/calc_delete_bitmap_executor.h"
#include "olap/delete_bitmap_calculator.h"
#include "olap/iterators.h"
#include "olap/memtable.h"
#include "olap/partial_update_info.h"
#include "olap/primary_key_index.h"
Expand Down Expand Up @@ -81,7 +82,9 @@ Status _get_segment_column_iterator(const BetaRowsetSharedPtr& rowset, uint32_t
rowset->rowset_id().to_string(), segid));
}
segment_v2::SegmentSharedPtr segment = *it;
RETURN_IF_ERROR(segment->new_column_iterator(target_column, column_iterator, nullptr));
StorageReadOptions opts;
opts.stats = stats;
RETURN_IF_ERROR(segment->new_column_iterator(target_column, column_iterator, &opts));
segment_v2::ColumnIteratorOptions opt {
.use_page_cache = !config::disable_storage_page_cache,
.file_reader = segment->file_reader().get(),
Expand Down
24 changes: 24 additions & 0 deletions be/src/olap/olap_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,30 @@ struct OlapReaderStatistics {
int64_t collect_iterator_merge_next_timer = 0;
int64_t collect_iterator_normal_next_timer = 0;
int64_t delete_bitmap_get_agg_ns = 0;

int64_t tablet_reader_init_timer_ns = 0;
int64_t tablet_reader_capture_rs_readers_timer_ns = 0;
int64_t tablet_reader_init_return_columns_timer_ns = 0;
int64_t tablet_reader_init_keys_param_timer_ns = 0;
int64_t tablet_reader_init_orderby_keys_param_timer_ns = 0;
int64_t tablet_reader_init_conditions_param_timer_ns = 0;
int64_t tablet_reader_init_delete_condition_param_timer_ns = 0;
int64_t block_reader_vcollect_iter_init_timer_ns = 0;
int64_t block_reader_rs_readers_init_timer_ns = 0;
int64_t block_reader_build_heap_init_timer_ns = 0;

int64_t rowset_reader_get_segment_iterators_timer_ns = 0;
int64_t rowset_reader_create_iterators_timer_ns = 0;
int64_t rowset_reader_init_iterators_timer_ns = 0;
int64_t rowset_reader_load_segments_timer_ns = 0;

int64_t segment_iterator_init_timer_ns = 0;
int64_t segment_iterator_init_return_column_iterators_timer_ns = 0;
int64_t segment_iterator_init_bitmap_index_iterators_timer_ns = 0;
int64_t segment_iterator_init_inverted_index_iterators_timer_ns = 0;

int64_t segment_create_column_readers_timer_ns = 0;
int64_t segment_load_index_timer_ns = 0;
};

using ColumnId = uint32_t;
Expand Down
21 changes: 14 additions & 7 deletions be/src/olap/rowset/beta_rowset_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ bool BetaRowsetReader::update_profile(RuntimeProfile* profile) {
Status BetaRowsetReader::get_segment_iterators(RowsetReaderContext* read_context,
std::vector<RowwiseIteratorUPtr>* out_iters,
bool use_cache) {
RETURN_IF_ERROR(_rowset->load());
_read_context = read_context;
// The segment iterator is created with its own statistics,
// and the member variable '_stats' is initialized by '_stats(&owned_stats)'.
Expand All @@ -92,6 +91,9 @@ Status BetaRowsetReader::get_segment_iterators(RowsetReaderContext* read_context
if (_read_context->stats != nullptr) {
_stats = _read_context->stats;
}
SCOPED_RAW_TIMER(&_stats->rowset_reader_get_segment_iterators_timer_ns);

RETURN_IF_ERROR(_rowset->load());

// convert RowsetReaderContext to StorageReadOptions
_read_options.block_row_max = read_context->batch_size;
Expand Down Expand Up @@ -225,9 +227,12 @@ Status BetaRowsetReader::get_segment_iterators(RowsetReaderContext* read_context
bool should_use_cache = use_cache || (_read_context->reader_type == ReaderType::READER_QUERY &&
enable_segment_cache);
SegmentCacheHandle segment_cache_handle;
RETURN_IF_ERROR(SegmentLoader::instance()->load_segments(_rowset, &segment_cache_handle,
should_use_cache,
/*need_load_pk_index_and_bf*/ false));
{
SCOPED_RAW_TIMER(&_stats->rowset_reader_load_segments_timer_ns);
RETURN_IF_ERROR(SegmentLoader::instance()->load_segments(
_rowset, &segment_cache_handle, should_use_cache,
/*need_load_pk_index_and_bf*/ false));
}

// create iterator for each segment
auto& segments = segment_cache_handle.get_segments();
Expand All @@ -253,6 +258,7 @@ Status BetaRowsetReader::get_segment_iterators(RowsetReaderContext* read_context
const bool use_lazy_init_iterators =
!is_merge_iterator && _read_context->reader_type == ReaderType::READER_QUERY;
for (int i = seg_start; i < seg_end; i++) {
SCOPED_RAW_TIMER(&_stats->rowset_reader_create_iterators_timer_ns);
auto& seg_ptr = segments[i];
std::unique_ptr<RowwiseIterator> iter;

Expand Down Expand Up @@ -317,6 +323,8 @@ Status BetaRowsetReader::_init_iterator() {
std::vector<RowwiseIteratorUPtr> iterators;
RETURN_IF_ERROR(get_segment_iterators(_read_context, &iterators));

SCOPED_RAW_TIMER(&_stats->rowset_reader_init_iterators_timer_ns);

if (_read_context->merged_rows == nullptr) {
_read_context->merged_rows = &_merged_rows;
}
Expand Down Expand Up @@ -352,8 +360,8 @@ Status BetaRowsetReader::_init_iterator() {
}

Status BetaRowsetReader::next_block(vectorized::Block* block) {
SCOPED_RAW_TIMER(&_stats->block_fetch_ns);
RETURN_IF_ERROR(_init_iterator_once());
SCOPED_RAW_TIMER(&_stats->block_fetch_ns);
if (_empty) {
return Status::Error<END_OF_FILE>("BetaRowsetReader is empty");
}
Expand Down Expand Up @@ -381,9 +389,8 @@ Status BetaRowsetReader::next_block(vectorized::Block* block) {
}

Status BetaRowsetReader::next_block_view(vectorized::BlockView* block_view) {
SCOPED_RAW_TIMER(&_stats->block_fetch_ns);
RETURN_IF_ERROR(_init_iterator_once());

SCOPED_RAW_TIMER(&_stats->block_fetch_ns);
RuntimeState* runtime_state = nullptr;
if (_read_context != nullptr) {
runtime_state = _read_context->runtime_state;
Expand Down
26 changes: 17 additions & 9 deletions be/src/olap/rowset/segment_v2/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ Status Segment::new_iterator(SchemaSPtr schema, const StorageReadOptions& read_o
if (read_options.runtime_state != nullptr) {
_be_exec_version = read_options.runtime_state->be_exec_version();
}
RETURN_IF_ERROR(_create_column_readers_once());
RETURN_IF_ERROR(_create_column_readers_once(read_options.stats));

read_options.stats->total_segment_number++;
// trying to prune the current segment by segment-level zone map
Expand Down Expand Up @@ -288,7 +288,11 @@ Status Segment::new_iterator(SchemaSPtr schema, const StorageReadOptions& read_o
}
}

RETURN_IF_ERROR(load_index());
{
SCOPED_RAW_TIMER(&read_options.stats->segment_load_index_timer_ns);
RETURN_IF_ERROR(load_index());
}

if (read_options.delete_condition_predicates->num_of_column_predicate() == 0 &&
read_options.push_down_agg_type_opt != TPushAggOp::NONE &&
read_options.push_down_agg_type_opt != TPushAggOp::COUNT_ON_INDEX) {
Expand Down Expand Up @@ -594,7 +598,8 @@ vectorized::DataTypePtr Segment::get_data_type_of(const ColumnIdentifier& identi
return nullptr;
}

Status Segment::_create_column_readers_once() {
Status Segment::_create_column_readers_once(OlapReaderStatistics* stats) {
SCOPED_RAW_TIMER(&stats->segment_create_column_readers_timer_ns);
return _create_column_readers_once_call.call([&] {
DCHECK(_footer_pb);
Defer defer([&]() { _footer_pb.reset(); });
Expand Down Expand Up @@ -868,10 +873,10 @@ Status Segment::new_column_iterator_with_path(const TabletColumn& tablet_column,
Status Segment::new_column_iterator(const TabletColumn& tablet_column,
std::unique_ptr<ColumnIterator>* iter,
const StorageReadOptions* opt) {
if (opt != nullptr && opt->runtime_state != nullptr) {
if (opt->runtime_state != nullptr) {
_be_exec_version = opt->runtime_state->be_exec_version();
}
RETURN_IF_ERROR(_create_column_readers_once());
RETURN_IF_ERROR(_create_column_readers_once(opt->stats));

// init column iterator by path info
if (tablet_column.has_path_info() || tablet_column.is_variant_type()) {
Expand Down Expand Up @@ -899,8 +904,9 @@ Status Segment::new_column_iterator(const TabletColumn& tablet_column,
return Status::OK();
}

Status Segment::new_column_iterator(int32_t unique_id, std::unique_ptr<ColumnIterator>* iter) {
RETURN_IF_ERROR(_create_column_readers_once());
Status Segment::new_column_iterator(int32_t unique_id, const StorageReadOptions* opt,
std::unique_ptr<ColumnIterator>* iter) {
RETURN_IF_ERROR(_create_column_readers_once(opt->stats));
ColumnIterator* it;
RETURN_IF_ERROR(_column_readers.at(unique_id)->new_iterator(&it));
iter->reset(it);
Expand Down Expand Up @@ -928,8 +934,9 @@ ColumnReader* Segment::_get_column_reader(const TabletColumn& col) {
}

Status Segment::new_bitmap_index_iterator(const TabletColumn& tablet_column,
const StorageReadOptions& read_options,
std::unique_ptr<BitmapIndexIterator>* iter) {
RETURN_IF_ERROR(_create_column_readers_once());
RETURN_IF_ERROR(_create_column_readers_once(read_options.stats));
ColumnReader* reader = _get_column_reader(tablet_column);
if (reader != nullptr && reader->has_bitmap_index()) {
BitmapIndexIterator* it;
Expand All @@ -947,7 +954,7 @@ Status Segment::new_inverted_index_iterator(const TabletColumn& tablet_column,
if (read_options.runtime_state != nullptr) {
_be_exec_version = read_options.runtime_state->be_exec_version();
}
RETURN_IF_ERROR(_create_column_readers_once());
RETURN_IF_ERROR(_create_column_readers_once(read_options.stats));
ColumnReader* reader = _get_column_reader(tablet_column);
if (reader != nullptr && index_meta) {
if (_inverted_index_file_reader == nullptr) {
Expand Down Expand Up @@ -1116,6 +1123,7 @@ Status Segment::seek_and_read_by_rowid(const TabletSchema& schema, SlotDescripto
OlapReaderStatistics& stats,
std::unique_ptr<ColumnIterator>& iterator_hint) {
StorageReadOptions storage_read_opt;
storage_read_opt.stats = &stats;
storage_read_opt.io_ctx.reader_type = ReaderType::READER_QUERY;
segment_v2::ColumnIteratorOptions opt {
.use_page_cache = !config::disable_storage_page_cache,
Expand Down
6 changes: 4 additions & 2 deletions be/src/olap/rowset/segment_v2/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ class Segment : public std::enable_shared_from_this<Segment>, public MetadataAdd
std::unique_ptr<ColumnIterator>* iter,
const StorageReadOptions* opt);

Status new_column_iterator(int32_t unique_id, std::unique_ptr<ColumnIterator>* iter);
Status new_column_iterator(int32_t unique_id, const StorageReadOptions* opt,
std::unique_ptr<ColumnIterator>* iter);

Status new_bitmap_index_iterator(const TabletColumn& tablet_column,
const StorageReadOptions& read_options,
std::unique_ptr<BitmapIndexIterator>* iter);

Status new_inverted_index_iterator(const TabletColumn& tablet_column,
Expand Down Expand Up @@ -238,7 +240,7 @@ class Segment : public std::enable_shared_from_this<Segment>, public MetadataAdd

Status _open_inverted_index();

Status _create_column_readers_once();
Status _create_column_readers_once(OlapReaderStatistics* stats);

private:
friend class SegmentIterator;
Expand Down
10 changes: 7 additions & 3 deletions be/src/olap/rowset/segment_v2/segment_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@ Status SegmentIterator::_init_impl(const StorageReadOptions& opts) {
if (_inited) {
return Status::OK();
}
_opts = opts;
SCOPED_RAW_TIMER(&_opts.stats->segment_iterator_init_timer_ns);
_inited = true;
_file_reader = _segment->_file_reader;
_opts = opts;
_col_predicates.clear();

for (const auto& predicate : opts.column_predicates) {
Expand Down Expand Up @@ -1005,6 +1006,7 @@ bool SegmentIterator::_check_all_conditions_passed_inverted_index_for_column(Col
}

Status SegmentIterator::_init_return_column_iterators() {
SCOPED_RAW_TIMER(&_opts.stats->segment_iterator_init_return_column_iterators_timer_ns);
if (_cur_rowid >= num_rows()) {
return Status::OK();
}
Expand Down Expand Up @@ -1047,19 +1049,21 @@ Status SegmentIterator::_init_return_column_iterators() {
}

Status SegmentIterator::_init_bitmap_index_iterators() {
SCOPED_RAW_TIMER(&_opts.stats->segment_iterator_init_bitmap_index_iterators_timer_ns);
if (_cur_rowid >= num_rows()) {
return Status::OK();
}
for (auto cid : _schema->column_ids()) {
if (_bitmap_index_iterators[cid] == nullptr) {
RETURN_IF_ERROR(_segment->new_bitmap_index_iterator(_opts.tablet_schema->column(cid),
&_bitmap_index_iterators[cid]));
RETURN_IF_ERROR(_segment->new_bitmap_index_iterator(
_opts.tablet_schema->column(cid), _opts, &_bitmap_index_iterators[cid]));
}
}
return Status::OK();
}

Status SegmentIterator::_init_inverted_index_iterators() {
SCOPED_RAW_TIMER(&_opts.stats->segment_iterator_init_inverted_index_iterators_timer_ns);
if (_cur_rowid >= num_rows()) {
return Status::OK();
}
Expand Down
7 changes: 7 additions & 0 deletions be/src/olap/tablet_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ TabletReader::~TabletReader() {
}

Status TabletReader::init(const ReaderParams& read_params) {
SCOPED_RAW_TIMER(&_stats.tablet_reader_init_timer_ns);
_predicate_arena = std::make_unique<vectorized::Arena>();

Status res = _init_params(read_params);
Expand Down Expand Up @@ -159,6 +160,7 @@ bool TabletReader::_optimize_for_single_rowset(
}

Status TabletReader::_capture_rs_readers(const ReaderParams& read_params) {
SCOPED_RAW_TIMER(&_stats.tablet_reader_capture_rs_readers_timer_ns);
if (read_params.rs_splits.empty()) {
return Status::InternalError("fail to acquire data sources. tablet={}",
_tablet->tablet_id());
Expand Down Expand Up @@ -331,6 +333,7 @@ Status TabletReader::_init_params(const ReaderParams& read_params) {
}

Status TabletReader::_init_return_columns(const ReaderParams& read_params) {
SCOPED_RAW_TIMER(&_stats.tablet_reader_init_return_columns_timer_ns);
if (read_params.reader_type == ReaderType::READER_QUERY) {
_return_columns = read_params.return_columns;
_tablet_columns_convert_to_null_set = read_params.tablet_columns_convert_to_null_set;
Expand Down Expand Up @@ -387,6 +390,7 @@ Status TabletReader::_init_return_columns(const ReaderParams& read_params) {
}

Status TabletReader::_init_keys_param(const ReaderParams& read_params) {
SCOPED_RAW_TIMER(&_stats.tablet_reader_init_keys_param_timer_ns);
if (read_params.start_key.empty()) {
return Status::OK();
}
Expand Down Expand Up @@ -461,6 +465,7 @@ Status TabletReader::_init_keys_param(const ReaderParams& read_params) {
}

Status TabletReader::_init_orderby_keys_param(const ReaderParams& read_params) {
SCOPED_RAW_TIMER(&_stats.tablet_reader_init_orderby_keys_param_timer_ns);
// UNIQUE_KEYS will compare all keys as before
if (_tablet_schema->keys_type() == DUP_KEYS || (_tablet_schema->keys_type() == UNIQUE_KEYS &&
_tablet->enable_unique_key_merge_on_write())) {
Expand Down Expand Up @@ -513,6 +518,7 @@ Status TabletReader::_init_orderby_keys_param(const ReaderParams& read_params) {
}

Status TabletReader::_init_conditions_param(const ReaderParams& read_params) {
SCOPED_RAW_TIMER(&_stats.tablet_reader_init_conditions_param_timer_ns);
std::vector<ColumnPredicate*> predicates;
for (const auto& condition : read_params.conditions) {
TCondition tmp_cond = condition;
Expand Down Expand Up @@ -639,6 +645,7 @@ ColumnPredicate* TabletReader::_parse_to_predicate(const FunctionFilter& functio
}

Status TabletReader::_init_delete_condition(const ReaderParams& read_params) {
SCOPED_RAW_TIMER(&_stats.tablet_reader_init_delete_condition_param_timer_ns);
// If it's cumu and not allow do delete when cumu
if (read_params.reader_type == ReaderType::READER_SEGMENT_COMPACTION ||
(read_params.reader_type == ReaderType::READER_CUMULATIVE_COMPACTION &&
Expand Down
41 changes: 41 additions & 0 deletions be/src/pipeline/exec/olap_scan_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,47 @@ Status OlapScanLocalState::_init_profile() {
_tablet_counter = ADD_COUNTER(_runtime_profile, "TabletNum", TUnit::UNIT);
_key_range_counter = ADD_COUNTER(_runtime_profile, "KeyRangesNum", TUnit::UNIT);
_runtime_filter_info = ADD_LABEL_COUNTER_WITH_LEVEL(_runtime_profile, "RuntimeFilterInfo", 1);

_tablet_reader_init_timer = ADD_TIMER(_scanner_profile, "TabletReaderInitTimer");
_tablet_reader_capture_rs_readers_timer =
ADD_TIMER(_scanner_profile, "TabletReaderCaptureRsReadersTimer");
_tablet_reader_init_return_columns_timer =
ADD_TIMER(_scanner_profile, "TabletReaderInitReturnColumnsTimer");
_tablet_reader_init_keys_param_timer =
ADD_TIMER(_scanner_profile, "TabletReaderInitKeysParamTimer");
_tablet_reader_init_orderby_keys_param_timer =
ADD_TIMER(_scanner_profile, "TabletReaderInitOrderbyKeysParamTimer");
_tablet_reader_init_conditions_param_timer =
ADD_TIMER(_scanner_profile, "TabletReaderInitConditionsParamTimer");
_tablet_reader_init_delete_condition_param_timer =
ADD_TIMER(_scanner_profile, "TabletReaderInitDeleteConditionParamTimer");
_block_reader_vcollect_iter_init_timer =
ADD_TIMER(_scanner_profile, "BlockReaderVcollectIterInitTimer");
_block_reader_rs_readers_init_timer =
ADD_TIMER(_scanner_profile, "BlockReaderRsReadersInitTimer");
_block_reader_build_heap_init_timer =
ADD_TIMER(_scanner_profile, "BlockReaderBuildHeapInitTimer");

_rowset_reader_get_segment_iterators_timer =
ADD_TIMER(_scanner_profile, "RowsetReaderGetSegmentIteratorsTimer");
_rowset_reader_create_iterators_timer =
ADD_TIMER(_scanner_profile, "RowsetReaderCreateIteratorsTimer");
_rowset_reader_init_iterators_timer =
ADD_TIMER(_scanner_profile, "RowsetReaderInitIteratorsTimer");
_rowset_reader_load_segments_timer =
ADD_TIMER(_scanner_profile, "RowsetReaderLoadSegmentsTimer");

_segment_iterator_init_timer = ADD_TIMER(_scanner_profile, "SegmentIteratorInitTimer");
_segment_iterator_init_return_column_iterators_timer =
ADD_TIMER(_scanner_profile, "SegmentIteratorInitReturnColumnIteratorsTimer");
_segment_iterator_init_bitmap_index_iterators_timer =
ADD_TIMER(_scanner_profile, "SegmentIteratorInitBitmapIndexIteratorsTimer");
_segment_iterator_init_inverted_index_iterators_timer =
ADD_TIMER(_scanner_profile, "SegmentIteratorInitInvertedIndexIteratorsTimer");

_segment_create_column_readers_timer =
ADD_TIMER(_scanner_profile, "SegmentCreateColumnReadersTimer");
_segment_load_index_timer = ADD_TIMER(_scanner_profile, "SegmentLoadIndexTimer");
return Status::OK();
}

Expand Down
Loading

0 comments on commit e3f3f47

Please sign in to comment.