HappenLee commented on code in PR #60655:
URL: https://github.com/apache/doris/pull/60655#discussion_r2836046711


##########
be/src/udf/python/python_server.cpp:
##########
@@ -273,6 +281,77 @@ void PythonServerManager::shutdown() {
     _process_pools.clear();
 }
 
+void PythonServerManager::_start_memory_monitor_thread() {
+    if (_memory_monitor_thread) return;
+
+    _memory_monitor_thread = std::make_unique<std::thread>([this]() {
+        while (!_shutdown_flag.load(std::memory_order_acquire)) {
+            // Wait for interval or shutdown signal
+            {
+                std::unique_lock<std::mutex> lock(_memory_monitor_mutex);
+                _memory_monitor_cv.wait_for(lock, std::chrono::seconds(15), 
[this]() {
+                    return _shutdown_flag.load(std::memory_order_acquire);
+                });
+            }
+
+            if (_shutdown_flag.load(std::memory_order_acquire)) break;
+
+            _refresh_memory_stats();
+        }
+
+        LOG(INFO) << "Python process memory monitor thread exiting";
+    });
+}
+
+Status PythonServerManager::_read_process_memory(pid_t pid, size_t* rss_bytes, 
size_t* vms_bytes) {
+    // Read from /proc/{pid}/statm
+    // Format: size resident shared text lib data dt
+    std::string statm_path = fmt::format("/proc/{}/statm", pid);
+    std::ifstream statm_file(statm_path);
+
+    if (!statm_file.is_open()) {
+        return Status::InternalError("Cannot open {}", statm_path);
+    }
+
+    size_t vms_pages = 0, rss_pages = 0;
+    statm_file >> vms_pages >> rss_pages;
+
+    if (statm_file.fail()) {
+        return Status::InternalError("Failed to read {}", statm_path);
+    }
+
+    // Convert pages to bytes
+    long page_size = sysconf(_SC_PAGESIZE);
+    *rss_bytes = rss_pages * page_size;
+    *vms_bytes = vms_pages * page_size;
+
+    return Status::OK();
+}
+
+void PythonServerManager::_refresh_memory_stats() {
+    std::lock_guard<std::mutex> lock(_pools_mutex);
+
+    int64_t total_rss = 0;
+
+    for (const auto& [version, pool] : _process_pools) {
+        for (const auto& process : pool) {
+            if (!process || !process->is_alive()) continue;
+
+            size_t rss_bytes = 0, vms_bytes = 0;
+            Status s = _read_process_memory(process->get_child_pid(), 
&rss_bytes, &vms_bytes);

Review Comment:
   the vms_bytes seems unless please remove it



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to