github-actions[bot] commented on code in PR #39839:
URL: https://github.com/apache/doris/pull/39839#discussion_r1728544557


##########
be/src/exec/schema_scanner/schema_workload_group_resource_usage_scanner.cpp:
##########
@@ -0,0 +1,90 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "exec/schema_scanner/schema_workload_group_resource_usage_scanner.h"
+
+#include <iomanip>
+#include <iostream>
+
+#include "runtime/exec_env.h"
+#include "runtime/runtime_state.h"
+#include "runtime/workload_group/workload_group_manager.h"
+#include "vec/common/string_ref.h"
+#include "vec/core/block.h"
+#include "vec/data_types/data_type_factory.hpp"
+
+namespace doris {
+std::vector<SchemaScanner::ColumnDesc> 
SchemaBackendWorkloadGroupResourceUsage::_s_tbls_columns = {
+        //   name,       type,          size
+        {"BE_ID", TYPE_BIGINT, sizeof(int64_t), false},
+        {"WORKLOAD_GROUP_ID", TYPE_BIGINT, sizeof(int64_t), false},
+        {"MEMORY_USAGE_BYTES", TYPE_BIGINT, sizeof(int64_t), false},
+        {"CPU_USAGE_PERCENT", TYPE_DOUBLE, sizeof(double), false},
+        {"LOCAL_SCAN_BYTES_PER_SECOND", TYPE_BIGINT, sizeof(int64_t), false},
+        {"REMOTE_SCAN_BYTES_PER_SECOND", TYPE_BIGINT, sizeof(int64_t), false},
+};
+
+SchemaBackendWorkloadGroupResourceUsage::SchemaBackendWorkloadGroupResourceUsage()

Review Comment:
   warning: use '= default' to define a trivial default constructor 
[modernize-use-equals-default]
   
   
be/src/exec/schema_scanner/schema_workload_group_resource_usage_scanner.cpp:41:
   ```diff
   -         : SchemaScanner(_s_tbls_columns, 
TSchemaTableType::SCH_WORKLOAD_GROUP_RESOURCE_USAGE) {}
   +         : SchemaScanner(_s_tbls_columns, 
TSchemaTableType::SCH_WORKLOAD_GROUP_RESOURCE_USAGE) = default;
   ```
   



##########
be/src/exec/schema_scanner/schema_workload_group_resource_usage_scanner.cpp:
##########
@@ -0,0 +1,90 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "exec/schema_scanner/schema_workload_group_resource_usage_scanner.h"
+
+#include <iomanip>
+#include <iostream>
+
+#include "runtime/exec_env.h"
+#include "runtime/runtime_state.h"
+#include "runtime/workload_group/workload_group_manager.h"
+#include "vec/common/string_ref.h"
+#include "vec/core/block.h"
+#include "vec/data_types/data_type_factory.hpp"
+
+namespace doris {
+std::vector<SchemaScanner::ColumnDesc> 
SchemaBackendWorkloadGroupResourceUsage::_s_tbls_columns = {
+        //   name,       type,          size
+        {"BE_ID", TYPE_BIGINT, sizeof(int64_t), false},
+        {"WORKLOAD_GROUP_ID", TYPE_BIGINT, sizeof(int64_t), false},
+        {"MEMORY_USAGE_BYTES", TYPE_BIGINT, sizeof(int64_t), false},
+        {"CPU_USAGE_PERCENT", TYPE_DOUBLE, sizeof(double), false},
+        {"LOCAL_SCAN_BYTES_PER_SECOND", TYPE_BIGINT, sizeof(int64_t), false},
+        {"REMOTE_SCAN_BYTES_PER_SECOND", TYPE_BIGINT, sizeof(int64_t), false},
+};
+
+SchemaBackendWorkloadGroupResourceUsage::SchemaBackendWorkloadGroupResourceUsage()
+        : SchemaScanner(_s_tbls_columns, 
TSchemaTableType::SCH_WORKLOAD_GROUP_RESOURCE_USAGE) {}
+
+SchemaBackendWorkloadGroupResourceUsage::~SchemaBackendWorkloadGroupResourceUsage()
 {}

Review Comment:
   warning: use '= default' to define a trivial destructor 
[modernize-use-equals-default]
   
   ```suggestion
   
SchemaBackendWorkloadGroupResourceUsage::~SchemaBackendWorkloadGroupResourceUsage()
 = default;
   ```
   



##########
be/src/runtime/workload_management/io_throttle.cpp:
##########
@@ -0,0 +1,87 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#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);
+}
+
+bool IOThrottle::acquire(int64_t block_timeout_ms) {
+    if (_io_bytes_per_second_limit < 0) {
+        return true;
+    }
+
+    std::unique_lock<std::mutex> w_lock(_mutex);
+    int64_t current_time = GetCurrentTimeMicros();
+    int64_t block_finish_time = block_timeout_ms <= 0 ? 0 : current_time + 
block_timeout_ms * 1000;
+
+    while (current_time <= _next_io_time_micros) {
+        if (block_finish_time > 0 && current_time >= block_finish_time) {
+            return false;
+        }
+        wait_condition.wait_for(w_lock,
+                                std::chrono::microseconds(_next_io_time_micros 
- current_time));
+        current_time = GetCurrentTimeMicros();
+    }
+    return true;
+}
+
+bool IOThrottle::try_acquire() {

Review Comment:
   warning: method 'try_acquire' can be made const 
[readability-make-member-function-const]
   
   be/src/runtime/workload_management/io_throttle.h:37:
   ```diff
   -     bool try_acquire();
   +     bool try_acquire() const;
   ```
   
   ```suggestion
   bool IOThrottle::try_acquire() const {
   ```
   



##########
be/src/runtime/workload_group/workload_group_manager.cpp:
##########
@@ -241,6 +242,52 @@ void WorkloadGroupMgr::refresh_wg_weighted_memory_ratio() {
     }
 }
 
+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;

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;
   ```
   



##########
be/src/runtime/workload_management/io_throttle.cpp:
##########
@@ -0,0 +1,87 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#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);
+}
+
+bool IOThrottle::acquire(int64_t block_timeout_ms) {
+    if (_io_bytes_per_second_limit < 0) {
+        return true;
+    }
+
+    std::unique_lock<std::mutex> w_lock(_mutex);
+    int64_t current_time = GetCurrentTimeMicros();
+    int64_t block_finish_time = block_timeout_ms <= 0 ? 0 : current_time + 
block_timeout_ms * 1000;
+
+    while (current_time <= _next_io_time_micros) {
+        if (block_finish_time > 0 && current_time >= block_finish_time) {
+            return false;
+        }
+        wait_condition.wait_for(w_lock,
+                                std::chrono::microseconds(_next_io_time_micros 
- current_time));
+        current_time = GetCurrentTimeMicros();
+    }
+    return true;
+}
+
+bool IOThrottle::try_acquire() {
+    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) {
+    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_limit;
+    {
+        std::unique_lock<std::mutex> w_lock(_mutex);
+        double io_bytes_float = static_cast<double>(io_bytes);

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_management/io_throttle.h:
##########
@@ -0,0 +1,56 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <bvar/bvar.h>
+#include <stdint.h>

Review Comment:
   warning: inclusion of deprecated C++ header 'stdint.h'; consider using 
'cstdint' instead [modernize-deprecated-headers]
   
   ```suggestion
   #include <cstdint>
   ```
   



##########
be/src/runtime/workload_management/io_throttle.cpp:
##########
@@ -0,0 +1,87 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#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);
+}
+
+bool IOThrottle::acquire(int64_t block_timeout_ms) {

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_group/workload_group.h:
##########
@@ -17,6 +17,7 @@
 
 #pragma once
 
+#include <bvar/bvar.h>

Review Comment:
   warning: 'bvar/bvar.h' file not found [clang-diagnostic-error]
   ```cpp
   #include <bvar/bvar.h>
            ^
   ```
   



##########
be/src/runtime/workload_management/io_throttle.h:
##########
@@ -0,0 +1,56 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <bvar/bvar.h>

Review Comment:
   warning: 'bvar/bvar.h' file not found [clang-diagnostic-error]
   ```cpp
   #include <bvar/bvar.h>
            ^
   ```
   



-- 
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

Reply via email to