-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[debug](rpc) debug rpc time consumption problem #39852
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| #include <gen_cpp/Types_types.h> | ||
| #include <glog/logging.h> | ||
| #include <google/protobuf/stubs/callback.h> | ||
| #include <pdqsort.h> | ||
| #include <stddef.h> | ||
|
|
||
| #include <atomic> | ||
|
|
@@ -176,7 +177,8 @@ void ExchangeSinkBuffer<Parent>::register_sink(TUniqueId fragment_instance_id) { | |
| _rpc_channel_is_idle[low_id] = true; | ||
| _instance_to_rpc_ctx[low_id] = {}; | ||
| _instance_to_receiver_eof[low_id] = false; | ||
| _instance_to_rpc_time[low_id] = 0; | ||
| _instance_to_rpc_stats_vec.emplace_back(std::make_shared<RpcInstanceStatistics>(low_id)); | ||
| _instance_to_rpc_stats[low_id] = _instance_to_rpc_stats_vec.back().get(); | ||
| _construct_request(low_id, finst_id); | ||
| } | ||
|
|
||
|
|
@@ -298,7 +300,10 @@ Status ExchangeSinkBuffer<Parent>::_send_rpc(InstanceLoId id) { | |
| } | ||
| // attach task for memory tracker and query id when core | ||
| SCOPED_ATTACH_TASK(_state); | ||
| set_rpc_time(id, start_rpc_time, result.receive_time()); | ||
| if (_state->enable_verbose_profile()) { | ||
| auto end_rpc_time = GetCurrentTimeNanos(); | ||
| update_rpc_time(id, start_rpc_time, end_rpc_time); | ||
| } | ||
| Status s(Status::create(result.status())); | ||
| if (s.is<ErrorCode::END_OF_FILE>()) { | ||
| _set_receiver_eof(id); | ||
|
|
@@ -376,7 +381,10 @@ Status ExchangeSinkBuffer<Parent>::_send_rpc(InstanceLoId id) { | |
| } | ||
| // attach task for memory tracker and query id when core | ||
| SCOPED_ATTACH_TASK(_state); | ||
| set_rpc_time(id, start_rpc_time, result.receive_time()); | ||
| if (_state->enable_verbose_profile()) { | ||
| auto end_rpc_time = GetCurrentTimeNanos(); | ||
| update_rpc_time(id, start_rpc_time, end_rpc_time); | ||
| } | ||
| Status s(Status::create(result.status())); | ||
| if (s.is<ErrorCode::END_OF_FILE>()) { | ||
| _set_receiver_eof(id); | ||
|
|
@@ -491,10 +499,10 @@ template <typename Parent> | |
| void ExchangeSinkBuffer<Parent>::get_max_min_rpc_time(int64_t* max_time, int64_t* min_time) { | ||
| int64_t local_max_time = 0; | ||
| int64_t local_min_time = INT64_MAX; | ||
| for (auto& [id, time] : _instance_to_rpc_time) { | ||
| if (time != 0) { | ||
| local_max_time = std::max(local_max_time, time); | ||
| local_min_time = std::min(local_min_time, time); | ||
| for (auto& [id, stats] : _instance_to_rpc_stats) { | ||
| if (stats->sum_time != 0) { | ||
| local_max_time = std::max(local_max_time, stats->sum_time); | ||
| local_min_time = std::min(local_min_time, stats->sum_time); | ||
| } | ||
| } | ||
| *max_time = local_max_time; | ||
|
|
@@ -504,20 +512,25 @@ void ExchangeSinkBuffer<Parent>::get_max_min_rpc_time(int64_t* max_time, int64_t | |
| template <typename Parent> | ||
| int64_t ExchangeSinkBuffer<Parent>::get_sum_rpc_time() { | ||
| int64_t sum_time = 0; | ||
| for (auto& [id, time] : _instance_to_rpc_time) { | ||
| sum_time += time; | ||
| for (auto& [id, stats] : _instance_to_rpc_stats) { | ||
| sum_time += stats->sum_time; | ||
| } | ||
| return sum_time; | ||
| } | ||
|
|
||
| template <typename Parent> | ||
| void ExchangeSinkBuffer<Parent>::set_rpc_time(InstanceLoId id, int64_t start_rpc_time, | ||
| int64_t receive_rpc_time) { | ||
| void ExchangeSinkBuffer<Parent>::update_rpc_time(InstanceLoId id, int64_t start_rpc_time, | ||
| int64_t receive_rpc_time) { | ||
| _rpc_count++; | ||
| int64_t rpc_spend_time = receive_rpc_time - start_rpc_time; | ||
| DCHECK(_instance_to_rpc_time.find(id) != _instance_to_rpc_time.end()); | ||
| DCHECK(_instance_to_rpc_stats.find(id) != _instance_to_rpc_stats.end()); | ||
| if (rpc_spend_time > 0) { | ||
| _instance_to_rpc_time[id] += rpc_spend_time; | ||
| ++_instance_to_rpc_stats[id]->rpc_count; | ||
| _instance_to_rpc_stats[id]->sum_time += rpc_spend_time; | ||
| _instance_to_rpc_stats[id]->max_time = | ||
| std::max(_instance_to_rpc_stats[id]->max_time, rpc_spend_time); | ||
| _instance_to_rpc_stats[id]->min_time = | ||
| std::min(_instance_to_rpc_stats[id]->min_time, rpc_spend_time); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -538,6 +551,36 @@ void ExchangeSinkBuffer<Parent>::update_profile(RuntimeProfile* profile) { | |
| int64_t sum_time = get_sum_rpc_time(); | ||
| _sum_rpc_timer->set(sum_time); | ||
| _avg_rpc_timer->set(sum_time / std::max(static_cast<int64_t>(1), _rpc_count.load())); | ||
|
|
||
| if constexpr (std::is_same_v<ExchangeSinkLocalState, Parent>) { | ||
| auto max_count = _state->rpc_verbose_profile_max_instance_count(); | ||
| if (_state->enable_verbose_profile() && max_count > 0) { | ||
| pdqsort(_instance_to_rpc_stats_vec.begin(), _instance_to_rpc_stats_vec.end(), | ||
| [](const auto& a, const auto& b) { return a->max_time > b->max_time; }); | ||
| auto count = std::min((size_t)max_count, _instance_to_rpc_stats_vec.size()); | ||
| int i = 0; | ||
| auto* detail_profile = profile->create_child("RpcInstanceDetails", true, true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个profile 对象得检查下是否为nullptr |
||
| for (const auto& stats : _instance_to_rpc_stats_vec) { | ||
| if (0 == stats->rpc_count) { | ||
| continue; | ||
| } | ||
| std::stringstream out; | ||
| out << "Instance " << std::hex << stats->inst_lo_id; | ||
| auto stats_str = fmt::format( | ||
| "Count: {}, MaxTime: {}, MinTime: {}, AvgTime: {}, SumTime: {}", | ||
| stats->rpc_count, PrettyPrinter::print(stats->max_time, TUnit::TIME_NS), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CloseTime: avg 11.310us, max 11.310us, min 11.310us |
||
| PrettyPrinter::print(stats->min_time, TUnit::TIME_NS), | ||
| PrettyPrinter::print(stats->sum_time / std::max(static_cast<int64_t>(1), | ||
| stats->rpc_count), | ||
| TUnit::TIME_NS), | ||
| PrettyPrinter::print(stats->sum_time, TUnit::TIME_NS)); | ||
| detail_profile->add_info_string(out.str(), stats_str); | ||
| if (++i == count) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| template class ExchangeSinkBuffer<vectorized::VDataStreamSender>; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.