yiguolei commented on code in PR #32641:
URL: https://github.com/apache/doris/pull/32641#discussion_r1542627384


##########
be/src/runtime/workload_group/workload_group_manager.cpp:
##########
@@ -135,6 +137,135 @@ void 
WorkloadGroupMgr::delete_workload_group_by_ids(std::set<uint64_t> used_wg_i
               << "ms, deleted group size:" << deleted_task_groups.size();
 }
 
+struct WorkloadGroupMemInfo {
+    int64_t total_mem_used = 0;
+    int64_t weighted_mem_used = 0;
+    bool is_low_wartermark = false;
+    bool is_high_wartermark = false;
+    double mem_used_ratio = 0;
+};
+void WorkloadGroupMgr::refresh_wg_memory_info() {
+    std::shared_lock<std::shared_mutex> r_lock(_group_mutex);
+    // workload group id -> workload group queries
+    std::unordered_map<uint64_t, std::unordered_map<TUniqueId, 
std::weak_ptr<QueryContext>>>
+            all_wg_queries;
+    for (auto& [wg_id, wg] : _workload_groups) {
+        all_wg_queries.insert({wg_id, wg->queries()});
+    }
+
+    int64_t all_queries_mem_used = 0;
+
+    // calculate total memory used of each workload group and total memory 
used of all queries
+    std::unordered_map<uint64_t, WorkloadGroupMemInfo> wgs_mem_info;
+    for (auto& [wg_id, wg_queries] : all_wg_queries) {
+        int64_t wg_total_mem_used = 0;
+        for (const auto& [query_id, query_ctx_ptr] : wg_queries) {
+            if (auto query_ctx = query_ctx_ptr.lock()) {
+                wg_total_mem_used +=
+                        query_ctx->is_cancelled() ? 0 : 
query_ctx->query_mem_tracker->consumption();

Review Comment:
   这样可能不行,如果把canceled 设置为0,那么可能会oom,因为此时canceled的query 的内存还没释放。



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