-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[PipelineX](improvement) Prepare tasks in parallel (#40844) #40874
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 |
|---|---|---|
|
|
@@ -137,8 +137,10 @@ PipelineFragmentContext::~PipelineFragmentContext() { | |
| } | ||
| } | ||
| _tasks.clear(); | ||
| for (auto& runtime_state : _task_runtime_states) { | ||
| runtime_state.reset(); | ||
| for (auto& runtime_states : _task_runtime_states) { | ||
| for (auto& runtime_state : runtime_states) { | ||
| runtime_state.reset(); | ||
| } | ||
| } | ||
| _pipelines.clear(); | ||
| _sink.reset(); | ||
|
|
@@ -229,7 +231,8 @@ PipelinePtr PipelineFragmentContext::add_pipeline(PipelinePtr parent, int idx) { | |
| return pipeline; | ||
| } | ||
|
|
||
| Status PipelineFragmentContext::prepare(const doris::TPipelineFragmentParams& request) { | ||
| Status PipelineFragmentContext::prepare(const doris::TPipelineFragmentParams& request, | ||
| ThreadPool* thread_pool) { | ||
| if (_prepared) { | ||
| return Status::InternalError("Already prepared"); | ||
| } | ||
|
|
@@ -346,7 +349,7 @@ Status PipelineFragmentContext::prepare(const doris::TPipelineFragmentParams& re | |
| { | ||
| SCOPED_TIMER(_build_tasks_timer); | ||
| // 5. Build pipeline tasks and initialize local state. | ||
| RETURN_IF_ERROR(_build_pipeline_tasks(request)); | ||
| RETURN_IF_ERROR(_build_pipeline_tasks(request, thread_pool)); | ||
| } | ||
|
|
||
| _init_next_report_time(); | ||
|
|
@@ -355,17 +358,23 @@ Status PipelineFragmentContext::prepare(const doris::TPipelineFragmentParams& re | |
| return Status::OK(); | ||
| } | ||
|
|
||
| Status PipelineFragmentContext::_build_pipeline_tasks( | ||
| const doris::TPipelineFragmentParams& request) { | ||
| Status PipelineFragmentContext::_build_pipeline_tasks(const doris::TPipelineFragmentParams& request, | ||
|
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. warning: function '_build_pipeline_tasks' has cognitive complexity of 56 (threshold 50) [readability-function-cognitive-complexity] ^Additional contextbe/src/pipeline/pipeline_fragment_context.cpp:373: nesting level increased to 1 );
^be/src/pipeline/pipeline_fragment_context.cpp:378: nesting level increased to 2 gr;
^be/src/pipeline/pipeline_fragment_context.cpp:384: +3, including nesting penalty of 2, nesting level increased to 3 );
^be/src/pipeline/pipeline_fragment_context.cpp:387: +3, including nesting penalty of 2, nesting level increased to 3 }
^be/src/pipeline/pipeline_fragment_context.cpp:390: +3, including nesting penalty of 2, nesting level increased to 3 }
^be/src/pipeline/pipeline_fragment_context.cpp:393: +3, including nesting penalty of 2, nesting level increased to 3 }
^be/src/pipeline/pipeline_fragment_context.cpp:396: +3, including nesting penalty of 2, nesting level increased to 3 }
^be/src/pipeline/pipeline_fragment_context.cpp:501: nesting level increased to 2 te
^be/src/pipeline/pipeline_fragment_context.cpp:503: +3, including nesting penalty of 2, nesting level increased to 3 ]);
^be/src/common/status.h:628: expanded from macro 'RETURN_IF_ERROR' do { \
^be/src/pipeline/pipeline_fragment_context.cpp:503: +4, including nesting penalty of 3, nesting level increased to 4 ]);
^be/src/common/status.h:630: expanded from macro 'RETURN_IF_ERROR' if (UNLIKELY(!_status_.ok())) { \
^be/src/pipeline/pipeline_fragment_context.cpp:542: +1, including nesting penalty of 0, nesting level increased to 1 };
^be/src/pipeline/pipeline_fragment_context.cpp:549: +2, including nesting penalty of 1, nesting level increased to 2 0;
^be/src/pipeline/pipeline_fragment_context.cpp:550: +3, including nesting penalty of 2, nesting level increased to 3 ) {
^be/src/common/status.h:628: expanded from macro 'RETURN_IF_ERROR' do { \
^be/src/pipeline/pipeline_fragment_context.cpp:550: nesting level increased to 4 ) {
^be/src/pipeline/pipeline_fragment_context.cpp:555: +5, including nesting penalty of 4, nesting level increased to 5 ++;
^be/src/pipeline/pipeline_fragment_context.cpp:550: +4, including nesting penalty of 3, nesting level increased to 4 ) {
^be/src/common/status.h:630: expanded from macro 'RETURN_IF_ERROR' if (UNLIKELY(!_status_.ok())) { \
^be/src/pipeline/pipeline_fragment_context.cpp:561: +2, including nesting penalty of 1, nesting level increased to 2 m);
^be/src/pipeline/pipeline_fragment_context.cpp:563: +3, including nesting penalty of 2, nesting level increased to 3 k);
^be/src/pipeline/pipeline_fragment_context.cpp:564: +4, including nesting penalty of 3, nesting level increased to 4 ) {
^be/src/pipeline/pipeline_fragment_context.cpp:569: +1, nesting level increased to 1 }
^be/src/pipeline/pipeline_fragment_context.cpp:570: +2, including nesting penalty of 1, nesting level increased to 2 e {
^be/src/pipeline/pipeline_fragment_context.cpp:571: +3, including nesting penalty of 2, nesting level increased to 3 ) {
^be/src/common/status.h:628: expanded from macro 'RETURN_IF_ERROR' do { \
^be/src/pipeline/pipeline_fragment_context.cpp:571: +4, including nesting penalty of 3, nesting level increased to 4 ) {
^be/src/common/status.h:630: expanded from macro 'RETURN_IF_ERROR' if (UNLIKELY(!_status_.ok())) { \
^
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. warning: function '_build_pipeline_tasks' exceeds recommended size/complexity thresholds [readability-function-size] ^Additional contextbe/src/pipeline/pipeline_fragment_context.cpp:360: 218 lines including whitespace and comments (threshold 80) ^ |
||
| ThreadPool* thread_pool) { | ||
| _total_tasks = 0; | ||
| int target_size = request.local_params.size(); | ||
| const auto target_size = request.local_params.size(); | ||
| _tasks.resize(target_size); | ||
| _fragment_instance_ids.resize(target_size); | ||
| _runtime_filter_states.resize(target_size); | ||
| _task_runtime_states.resize(_pipelines.size()); | ||
| for (size_t pip_idx = 0; pip_idx < _pipelines.size(); pip_idx++) { | ||
| _task_runtime_states[pip_idx].resize(_pipelines[pip_idx]->num_tasks()); | ||
| } | ||
| auto pipeline_id_to_profile = _runtime_state->build_pipeline_profile(_pipelines.size()); | ||
|
|
||
| for (size_t i = 0; i < target_size; i++) { | ||
| auto pre_and_submit = [&](int i, PipelineFragmentContext* ctx) { | ||
| const auto& local_params = request.local_params[i]; | ||
| auto fragment_instance_id = local_params.fragment_instance_id; | ||
| _fragment_instance_ids.push_back(fragment_instance_id); | ||
| _fragment_instance_ids[i] = fragment_instance_id; | ||
| std::unique_ptr<RuntimeFilterMgr> runtime_filter_mgr; | ||
| auto init_runtime_state = [&](std::unique_ptr<RuntimeState>& runtime_state) { | ||
| runtime_state->set_query_mem_tracker(_query_ctx->query_mem_tracker); | ||
|
|
@@ -424,7 +433,7 @@ Status PipelineFragmentContext::_build_pipeline_tasks( | |
|
|
||
| filterparams->runtime_filter_mgr = runtime_filter_mgr.get(); | ||
|
|
||
| _runtime_filter_states.push_back(std::move(filterparams)); | ||
| _runtime_filter_states[i] = std::move(filterparams); | ||
| std::map<PipelineId, PipelineTask*> pipeline_id_to_task; | ||
| auto get_local_exchange_state = [&](PipelinePtr pipeline) | ||
| -> std::map<int, std::pair<std::shared_ptr<LocalExchangeSharedState>, | ||
|
|
@@ -447,13 +456,15 @@ Status PipelineFragmentContext::_build_pipeline_tasks( | |
|
|
||
| for (size_t pip_idx = 0; pip_idx < _pipelines.size(); pip_idx++) { | ||
| auto& pipeline = _pipelines[pip_idx]; | ||
| if (pipeline->need_to_create_task()) { | ||
| // build task runtime state | ||
| _task_runtime_states.push_back(RuntimeState::create_unique( | ||
| if (pipeline->num_tasks() > 1 || i == 0) { | ||
| DCHECK(_task_runtime_states[pip_idx][i] == nullptr) | ||
| << print_id(_task_runtime_states[pip_idx][i]->fragment_instance_id()) << " " | ||
| << pipeline->debug_string(); | ||
| _task_runtime_states[pip_idx][i] = RuntimeState::create_unique( | ||
| this, local_params.fragment_instance_id, request.query_id, | ||
| request.fragment_id, request.query_options, _query_ctx->query_globals, | ||
| _exec_env, _query_ctx.get())); | ||
| auto& task_runtime_state = _task_runtime_states.back(); | ||
| _exec_env, _query_ctx.get()); | ||
| auto& task_runtime_state = _task_runtime_states[pip_idx][i]; | ||
| init_runtime_state(task_runtime_state); | ||
| auto cur_task_id = _total_tasks++; | ||
| task_runtime_state->set_task_id(cur_task_id); | ||
|
|
@@ -527,6 +538,39 @@ Status PipelineFragmentContext::_build_pipeline_tasks( | |
| std::lock_guard<std::mutex> l(_state_map_lock); | ||
| _runtime_filter_mgr_map[fragment_instance_id] = std::move(runtime_filter_mgr); | ||
| } | ||
| return Status::OK(); | ||
| }; | ||
| if (target_size > 1 && | ||
| (_runtime_state->query_options().__isset.parallel_prepare_threshold && | ||
| target_size > _runtime_state->query_options().parallel_prepare_threshold)) { | ||
| std::vector<Status> prepare_status(target_size); | ||
| std::mutex m; | ||
| std::condition_variable cv; | ||
| int prepare_done = 0; | ||
| for (size_t i = 0; i < target_size; i++) { | ||
| RETURN_IF_ERROR(thread_pool->submit_func([&, i]() { | ||
| SCOPED_ATTACH_TASK(_query_ctx.get()); | ||
| prepare_status[i] = pre_and_submit(i, this); | ||
| std::unique_lock<std::mutex> lock(m); | ||
| prepare_done++; | ||
| if (prepare_done == target_size) { | ||
| cv.notify_one(); | ||
| } | ||
| })); | ||
| } | ||
| std::unique_lock<std::mutex> lock(m); | ||
| if (prepare_done != target_size) { | ||
| cv.wait(lock); | ||
| for (size_t i = 0; i < target_size; i++) { | ||
| if (!prepare_status[i].ok()) { | ||
| return prepare_status[i]; | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| for (size_t i = 0; i < target_size; i++) { | ||
| RETURN_IF_ERROR(pre_and_submit(i, this)); | ||
| } | ||
| } | ||
| _pipeline_parent_map.clear(); | ||
| _dag.clear(); | ||
|
|
@@ -1683,8 +1727,12 @@ Status PipelineFragmentContext::send_report(bool done) { | |
|
|
||
| std::vector<RuntimeState*> runtime_states; | ||
|
|
||
| for (auto& task_state : _task_runtime_states) { | ||
| runtime_states.push_back(task_state.get()); | ||
| for (auto& task_states : _task_runtime_states) { | ||
| for (auto& task_state : task_states) { | ||
| if (task_state) { | ||
| runtime_states.push_back(task_state.get()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| ReportStatusRequest req {exec_status, | ||
|
|
@@ -1755,15 +1803,17 @@ PipelineFragmentContext::collect_realtime_load_channel_profile_x() const { | |
| return nullptr; | ||
| } | ||
|
|
||
| for (auto& runtime_state : _task_runtime_states) { | ||
| if (runtime_state->runtime_profile() == nullptr) { | ||
| continue; | ||
| } | ||
| for (auto& runtime_states : _task_runtime_states) { | ||
| for (auto& runtime_state : runtime_states) { | ||
| if (runtime_state->runtime_profile() == nullptr) { | ||
| continue; | ||
| } | ||
|
|
||
| auto tmp_load_channel_profile = std::make_shared<TRuntimeProfileTree>(); | ||
| auto tmp_load_channel_profile = std::make_shared<TRuntimeProfileTree>(); | ||
|
|
||
| runtime_state->runtime_profile()->to_thrift(tmp_load_channel_profile.get()); | ||
| this->_runtime_state->load_channel_profile()->update(*tmp_load_channel_profile); | ||
| runtime_state->runtime_profile()->to_thrift(tmp_load_channel_profile.get()); | ||
| this->_runtime_state->load_channel_profile()->update(*tmp_load_channel_profile); | ||
| } | ||
| } | ||
|
|
||
| auto load_channel_profile = std::make_shared<TRuntimeProfileTree>(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: function 'prepare' exceeds recommended size/complexity thresholds [readability-function-size]
Additional context
be/src/pipeline/pipeline_fragment_context.cpp:233: 124 lines including whitespace and comments (threshold 80)