github-actions[bot] commented on code in PR #39177: URL: https://github.com/apache/doris/pull/39177#discussion_r1712572791
########## be/src/runtime/workload_management/io_throttle.cpp: ########## @@ -17,12 +17,19 @@ #include "runtime/workload_management/io_throttle.h" +#include "util/defer_op.h" #include "util/time.h" namespace doris { +IOThrottle::IOThrottle(std::string prefix, std::string name) { + _io_adder = std::make_unique<bvar::Adder<size_t>>(prefix, name); + _io_adder_per_second = std::make_unique<bvar::PerSecond<bvar::Adder<size_t>>>( + prefix, name + "_per_second", _io_adder.get(), 1); +} + Review Comment: warning: method 'acquire' can be made const [readability-make-member-function-const] be/src/runtime/workload_management/io_throttle.h:34: ```diff - bool acquire(int64_t block_timeout_ms); + bool acquire(int64_t block_timeout_ms) const; ``` ```suggestion bool IOThrottle::acquire(int64_t block_timeout_ms) const { ``` ########## be/src/runtime/workload_management/io_throttle.cpp: ########## @@ -42,32 +49,39 @@ } bool IOThrottle::try_acquire() { - if (_io_bytes_per_second < 0) { + if (_io_bytes_per_second_limit < 0) { return true; } std::unique_lock<std::mutex> w_lock(_mutex); return GetCurrentTimeMicros() > _next_io_time_micros; } void IOThrottle::update_next_io_time(int64_t io_bytes) { - if (_io_bytes_per_second <= 0 || io_bytes <= 0) { + Defer defer {[&]() { + if (io_bytes > 0) { + (*_io_adder) << io_bytes; + } + }}; + if (_io_bytes_per_second_limit <= 0 || io_bytes <= 0) { return; } - int64_t read_bytes_per_second = _io_bytes_per_second; - std::unique_lock<std::mutex> w_lock(_mutex); - double io_bytes_float = static_cast<double>(io_bytes); - double ret = (io_bytes_float / static_cast<double>(read_bytes_per_second)) * - static_cast<double>(MICROS_PER_SEC); - int64_t current_time = GetCurrentTimeMicros(); + int64_t read_bytes_per_second = _io_bytes_per_second_limit; + { + std::unique_lock<std::mutex> w_lock(_mutex); Review Comment: warning: use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto] ```suggestion auto io_bytes_float = static_cast<double>(io_bytes); ``` ########## be/src/runtime/workload_group/workload_group_manager.cpp: ########## @@ -257,6 +258,51 @@ void WorkloadGroupMgr::refresh_wg_weighted_memory_limit() { } } +void WorkloadGroupMgr::get_wg_resource_usage(vectorized::Block* block) { + auto insert_int_value = [&](int col_index, int64_t int_val, vectorized::Block* block) { + vectorized::MutableColumnPtr mutable_col_ptr; + mutable_col_ptr = std::move(*block->get_by_position(col_index).column).assume_mutable(); + auto* nullable_column = + reinterpret_cast<vectorized::ColumnNullable*>(mutable_col_ptr.get()); + vectorized::IColumn* col_ptr = &nullable_column->get_nested_column(); + reinterpret_cast<vectorized::ColumnVector<vectorized::Int64>*>(col_ptr)->insert_value( + int_val); + nullable_column->get_null_map_data().emplace_back(0); + }; + + auto insert_double_value = [&](int col_index, double double_val, vectorized::Block* block) { + vectorized::MutableColumnPtr mutable_col_ptr; + mutable_col_ptr = std::move(*block->get_by_position(col_index).column).assume_mutable(); + auto* nullable_column = + reinterpret_cast<vectorized::ColumnNullable*>(mutable_col_ptr.get()); + vectorized::IColumn* col_ptr = &nullable_column->get_nested_column(); + reinterpret_cast<vectorized::ColumnVector<vectorized::Float64>*>(col_ptr)->insert_value( + double_val); + nullable_column->get_null_map_data().emplace_back(0); + }; + + int64_t be_id = ExecEnv::GetInstance()->master_info()->backend_id; + int cpu_num = CpuInfo::num_cores(); + cpu_num = cpu_num <= 0 ? 1 : cpu_num; + uint64_t total_cpu_time_ns_per_second = cpu_num * 1000000000ll; + + std::shared_lock<std::shared_mutex> r_lock(_group_mutex); + block->reserve(_workload_groups.size()); + for (const auto& [id, wg] : _workload_groups) { + insert_int_value(0, be_id, block); + insert_int_value(1, wg->id(), block); + insert_int_value(2, wg->get_mem_used(), block); + + double cpu_usage_p = + (double)wg->get_cpu_usage() / (double)total_cpu_time_ns_per_second * 100; + Review Comment: warning: integer literal has suffix 'll', which is not uppercase [readability-uppercase-literal-suffix] ```suggestion uint64_t total_cpu_time_ns_per_second = cpu_num * 1000000000LL; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org