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

[Chore](metrics) remove trace metrics code using runtime profile instand #21394

Merged
merged 3 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions be/src/agent/task_worker_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1214,15 +1214,13 @@ void CreateTableTaskPool::_create_tablet_worker_thread_callback() {
_tasks.pop_front();
}
const TCreateTabletReq& create_tablet_req = agent_task_req.create_tablet_req;
scoped_refptr<Trace> trace(new Trace);
MonotonicStopWatch watch;
watch.start();
SCOPED_CLEANUP({
if (watch.elapsed_time() / 1e9 > config::agent_task_trace_threshold_sec) {
LOG(WARNING) << "Trace:" << std::endl << trace->DumpToString(Trace::INCLUDE_ALL);
LOG(WARNING) << "create tablet cost " << watch.elapsed_time() / 1e9;
}
});
ADOPT_TRACE(trace.get());
DorisMetrics::instance()->create_tablet_requests_total->increment(1);
VLOG_NOTICE << "start to create tablet " << create_tablet_req.tablet_id;

Expand Down
2 changes: 1 addition & 1 deletion be/src/olap/base_compaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Status BaseCompaction::prepare_compact() {

// 1. pick rowsets to compact
RETURN_IF_ERROR(pick_rowsets_to_compact());
TRACE_COUNTER_INCREMENT("input_rowsets_count", _input_rowsets.size());
COUNTER_UPDATE(_input_rowsets_counter, _input_rowsets.size());
_tablet->set_clone_occurred(false);

return Status::OK();
Expand Down
51 changes: 36 additions & 15 deletions be/src/olap/compaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,28 @@ Compaction::Compaction(const TabletSharedPtr& tablet, const std::string& label)
_input_index_size(0),
_state(CompactionState::INITED) {
_mem_tracker = std::make_shared<MemTrackerLimiter>(MemTrackerLimiter::Type::COMPACTION, label);
init_profile(label);
}

Compaction::~Compaction() {}

void Compaction::init_profile(const std::string& label) {
_profile = std::make_unique<RuntimeProfile>(label);

_input_rowsets_data_size_counter =
ADD_COUNTER(_profile, "input_rowsets_data_size", TUnit::BYTES);
_input_rowsets_counter = ADD_COUNTER(_profile, "input_rowsets_count", TUnit::UNIT);
_input_row_num_counter = ADD_COUNTER(_profile, "input_row_num", TUnit::UNIT);
_input_segments_num_counter = ADD_COUNTER(_profile, "input_segments_num", TUnit::UNIT);
_merged_rows_counter = ADD_COUNTER(_profile, "merged_rows", TUnit::UNIT);
_filtered_rows_counter = ADD_COUNTER(_profile, "filtered_rows", TUnit::UNIT);
_output_rowset_data_size_counter =
ADD_COUNTER(_profile, "output_rowset_data_size", TUnit::BYTES);
_output_row_num_counter = ADD_COUNTER(_profile, "output_row_num", TUnit::UNIT);
_output_segments_num_counter = ADD_COUNTER(_profile, "output_segments_num", TUnit::UNIT);
_merge_rowsets_latency_timer = ADD_TIMER(_profile, "merge_rowsets_latency");
}

Status Compaction::compact() {
RETURN_IF_ERROR(prepare_compact());
RETURN_IF_ERROR(execute_compact());
Expand Down Expand Up @@ -208,9 +226,9 @@ void Compaction::build_basic_info() {
_input_row_num += rowset->num_rows();
_input_num_segments += rowset->num_segments();
}
TRACE_COUNTER_INCREMENT("input_rowsets_data_size", _input_rowsets_size);
TRACE_COUNTER_INCREMENT("input_row_num", _input_row_num);
TRACE_COUNTER_INCREMENT("input_segments_num", _input_num_segments);
COUNTER_UPDATE(_input_rowsets_data_size_counter, _input_rowsets_size);
COUNTER_UPDATE(_input_row_num_counter, _input_row_num);
COUNTER_UPDATE(_input_segments_num_counter, _input_num_segments);

_output_version =
Version(_input_rowsets.front()->start_version(), _input_rowsets.back()->end_version());
Expand Down Expand Up @@ -315,13 +333,16 @@ Status Compaction::do_compaction_impl(int64_t permits) {
}

Status res;
if (vertical_compaction) {
res = Merger::vertical_merge_rowsets(_tablet, compaction_type(), _cur_tablet_schema,
_input_rs_readers, _output_rs_writer.get(),
get_avg_segment_rows(), &stats);
} else {
res = Merger::vmerge_rowsets(_tablet, compaction_type(), _cur_tablet_schema,
_input_rs_readers, _output_rs_writer.get(), &stats);
{
SCOPED_TIMER(_merge_rowsets_latency_timer);
if (vertical_compaction) {
res = Merger::vertical_merge_rowsets(_tablet, compaction_type(), _cur_tablet_schema,
_input_rs_readers, _output_rs_writer.get(),
get_avg_segment_rows(), &stats);
} else {
res = Merger::vmerge_rowsets(_tablet, compaction_type(), _cur_tablet_schema,
_input_rs_readers, _output_rs_writer.get(), &stats);
}
}

if (!res.ok()) {
Expand All @@ -330,8 +351,8 @@ Status Compaction::do_compaction_impl(int64_t permits) {
<< ", output_version=" << _output_version;
return res;
}
TRACE_COUNTER_INCREMENT("merged_rows", stats.merged_rows);
TRACE_COUNTER_INCREMENT("filtered_rows", stats.filtered_rows);
COUNTER_UPDATE(_merged_rows_counter, stats.merged_rows);
COUNTER_UPDATE(_filtered_rows_counter, stats.filtered_rows);

_output_rowset = _output_rs_writer->build();
if (_output_rowset == nullptr) {
Expand All @@ -340,9 +361,9 @@ Status Compaction::do_compaction_impl(int64_t permits) {
return Status::Error<ROWSET_BUILDER_INIT>();
}

TRACE_COUNTER_INCREMENT("output_rowset_data_size", _output_rowset->data_disk_size());
TRACE_COUNTER_INCREMENT("output_row_num", _output_rowset->num_rows());
TRACE_COUNTER_INCREMENT("output_segments_num", _output_rowset->num_segments());
COUNTER_UPDATE(_output_rowset_data_size_counter, _output_rowset->data_disk_size());
COUNTER_UPDATE(_output_row_num_counter, _output_rowset->num_rows());
COUNTER_UPDATE(_output_segments_num_counter, _output_rowset->num_segments());

// 3. check correctness
RETURN_IF_ERROR(check_correctness(stats));
Expand Down
17 changes: 17 additions & 0 deletions be/src/olap/compaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Compaction {
RowsetSharedPtr output_rowset();
#endif

RuntimeProfile* runtime_profile() const { return _profile.get(); }

protected:
virtual Status pick_rowsets_to_compact() = 0;
virtual std::string compaction_name() const = 0;
Expand Down Expand Up @@ -90,6 +92,8 @@ class Compaction {
bool is_rowset_tidy(std::string& pre_max_key, const RowsetSharedPtr& rhs);
void build_basic_info();

void init_profile(const std::string& label);

protected:
// the root tracker for this compaction
std::shared_ptr<MemTrackerLimiter> _mem_tracker;
Expand All @@ -115,6 +119,19 @@ class Compaction {
RowIdConversion _rowid_conversion;
TabletSchemaSPtr _cur_tablet_schema;

std::unique_ptr<RuntimeProfile> _profile;

RuntimeProfile::Counter* _input_rowsets_data_size_counter = nullptr;
RuntimeProfile::Counter* _input_rowsets_counter = nullptr;
RuntimeProfile::Counter* _input_row_num_counter = nullptr;
RuntimeProfile::Counter* _input_segments_num_counter = nullptr;
RuntimeProfile::Counter* _merged_rows_counter = nullptr;
RuntimeProfile::Counter* _filtered_rows_counter = nullptr;
RuntimeProfile::Counter* _output_rowset_data_size_counter = nullptr;
RuntimeProfile::Counter* _output_row_num_counter = nullptr;
RuntimeProfile::Counter* _output_segments_num_counter = nullptr;
RuntimeProfile::Counter* _merge_rowsets_latency_timer = nullptr;

DISALLOW_COPY_AND_ASSIGN(Compaction);
};

Expand Down
2 changes: 1 addition & 1 deletion be/src/olap/cumulative_compaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Status CumulativeCompaction::prepare_compact() {

// 2. pick rowsets to compact
RETURN_IF_ERROR(pick_rowsets_to_compact());
TRACE_COUNTER_INCREMENT("input_rowsets_count", _input_rowsets.size());
COUNTER_UPDATE(_input_rowsets_counter, _input_rowsets.size());
_tablet->set_clone_occurred(false);

return Status::OK();
Expand Down
3 changes: 0 additions & 3 deletions be/src/olap/merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "olap/tablet.h"
#include "olap/utils.h"
#include "util/slice.h"
#include "util/trace.h"
#include "vec/core/block.h"
#include "vec/olap/block_reader.h"
#include "vec/olap/vertical_block_reader.h"
Expand All @@ -57,8 +56,6 @@ Status Merger::vmerge_rowsets(TabletSharedPtr tablet, ReaderType reader_type,
TabletSchemaSPtr cur_tablet_schema,
const std::vector<RowsetReaderSharedPtr>& src_rowset_readers,
RowsetWriter* dst_rowset_writer, Statistics* stats_output) {
TRACE_COUNTER_SCOPE_LATENCY_US("merge_rowsets_latency_us");

vectorized::BlockReader reader;
TabletReader::ReaderParams reader_params;
reader_params.tablet = tablet;
Expand Down
43 changes: 24 additions & 19 deletions be/src/olap/tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1670,15 +1670,18 @@ Status Tablet::prepare_compaction_and_calculate_permits(CompactionType compactio
TabletSharedPtr tablet, int64_t* permits) {
std::vector<RowsetSharedPtr> compaction_rowsets;
if (compaction_type == CompactionType::CUMULATIVE_COMPACTION) {
scoped_refptr<Trace> trace(new Trace);
MonotonicStopWatch watch;
watch.start();
SCOPED_CLEANUP({
if (watch.elapsed_time() / 1e9 > config::cumulative_compaction_trace_threshold) {
LOG(WARNING) << "Trace:" << std::endl << trace->DumpToString(Trace::INCLUDE_ALL);
if (!config::disable_compaction_trace_log &&
watch.elapsed_time() / 1e9 > config::cumulative_compaction_trace_threshold) {
std::stringstream ss;
_cumulative_compaction->runtime_profile()->pretty_print(&ss);
LOG(WARNING) << "prepare cumulative compaction cost " << watch.elapsed_time() / 1e9
<< std::endl
<< ss.str();
}
});
ADOPT_TRACE(trace.get());

StorageEngine::instance()->create_cumulative_compaction(tablet, _cumulative_compaction);
DorisMetrics::instance()->cumulative_compaction_request_total->increment(1);
Expand All @@ -1698,15 +1701,18 @@ Status Tablet::prepare_compaction_and_calculate_permits(CompactionType compactio
compaction_rowsets = _cumulative_compaction->get_input_rowsets();
} else {
DCHECK_EQ(compaction_type, CompactionType::BASE_COMPACTION);
scoped_refptr<Trace> trace(new Trace);
MonotonicStopWatch watch;
watch.start();
SCOPED_CLEANUP({
if (watch.elapsed_time() / 1e9 > config::base_compaction_trace_threshold) {
LOG(WARNING) << "Trace:" << std::endl << trace->DumpToString(Trace::INCLUDE_ALL);
if (!config::disable_compaction_trace_log &&
watch.elapsed_time() / 1e9 > config::base_compaction_trace_threshold) {
std::stringstream ss;
_base_compaction->runtime_profile()->pretty_print(&ss);
LOG(WARNING) << "prepare base compaction cost " << watch.elapsed_time() / 1e9
<< std::endl
<< ss.str();
}
});
ADOPT_TRACE(trace.get());

StorageEngine::instance()->create_base_compaction(tablet, _base_compaction);
DorisMetrics::instance()->base_compaction_request_total->increment(1);
Expand Down Expand Up @@ -1734,9 +1740,6 @@ Status Tablet::prepare_compaction_and_calculate_permits(CompactionType compactio

Status Tablet::prepare_single_replica_compaction(TabletSharedPtr tablet,
CompactionType compaction_type) {
scoped_refptr<Trace> trace(new Trace);
ADOPT_TRACE(trace.get());

StorageEngine::instance()->create_single_replica_compaction(tablet, _single_replica_compaction,
compaction_type);
Status res = _single_replica_compaction->prepare_compact();
Expand All @@ -1749,8 +1752,6 @@ Status Tablet::prepare_single_replica_compaction(TabletSharedPtr tablet,
}

void Tablet::execute_single_replica_compaction(CompactionType compaction_type) {
scoped_refptr<Trace> trace(new Trace);
ADOPT_TRACE(trace.get());
Status res = _single_replica_compaction->execute_compact();
if (!res.ok()) {
if (compaction_type == CompactionType::CUMULATIVE_COMPACTION) {
Expand Down Expand Up @@ -1788,16 +1789,18 @@ std::vector<Version> Tablet::get_all_versions() {

void Tablet::execute_compaction(CompactionType compaction_type) {
if (compaction_type == CompactionType::CUMULATIVE_COMPACTION) {
scoped_refptr<Trace> trace(new Trace);
MonotonicStopWatch watch;
watch.start();
SCOPED_CLEANUP({
if (!config::disable_compaction_trace_log &&
watch.elapsed_time() / 1e9 > config::cumulative_compaction_trace_threshold) {
LOG(WARNING) << "Trace:" << std::endl << trace->DumpToString(Trace::INCLUDE_ALL);
std::stringstream ss;
_cumulative_compaction->runtime_profile()->pretty_print(&ss);
LOG(WARNING) << "execute cumulative compaction cost " << watch.elapsed_time() / 1e9
<< std::endl
<< ss.str();
}
});
ADOPT_TRACE(trace.get());

Status res = _cumulative_compaction->execute_compact();
if (!res.ok()) {
Expand All @@ -1810,16 +1813,18 @@ void Tablet::execute_compaction(CompactionType compaction_type) {
set_last_cumu_compaction_failure_time(0);
} else {
DCHECK_EQ(compaction_type, CompactionType::BASE_COMPACTION);
scoped_refptr<Trace> trace(new Trace);
MonotonicStopWatch watch;
watch.start();
SCOPED_CLEANUP({
if (!config::disable_compaction_trace_log &&
watch.elapsed_time() / 1e9 > config::base_compaction_trace_threshold) {
LOG(WARNING) << "Trace:" << std::endl << trace->DumpToString(Trace::INCLUDE_ALL);
std::stringstream ss;
_base_compaction->runtime_profile()->pretty_print(&ss);
LOG(WARNING) << "execute base compaction cost " << watch.elapsed_time() / 1e9
<< std::endl
<< ss.str();
}
});
ADOPT_TRACE(trace.get());

Status res = _base_compaction->execute_compact();
if (!res.ok()) {
Expand Down
Loading
Loading