This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new f0fab593f72 branch-4.1: [fix](be) Avoid per-fd stat when counting
process fds in metrics #67945 (#68046)
f0fab593f72 is described below
commit f0fab593f720eb7d21c62d3bf8c265b058f249b9
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Sep 16 16:22:58 2026 +0800
branch-4.1: [fix](be) Avoid per-fd stat when counting process fds in
metrics #67945 (#68046)
Cherry-picked from #67945
Co-authored-by: Yancy <[email protected]>
Co-authored-by: Asthenia0412 <[email protected]>
---
be/src/common/metrics/doris_metrics.cpp | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/be/src/common/metrics/doris_metrics.cpp
b/be/src/common/metrics/doris_metrics.cpp
index 715837f3bc1..63afd723822 100644
--- a/be/src/common/metrics/doris_metrics.cpp
+++ b/be/src/common/metrics/doris_metrics.cpp
@@ -494,11 +494,15 @@ void DorisMetrics::_update_process_fd_num() {
process_fd_num_used->set_value(0);
return;
}
- int64_t count =
- std::count_if(dict_iter, std::filesystem::end(dict_iter), [](const
auto& entry) {
- std::error_code error_code;
- return entry.is_regular_file(error_code) && !error_code;
- });
+ // Entries under /proc/self/fd are symlinks, and every is_regular_file()
call
+ // follows the link with a stat(), which is O(fds) syscalls and can stall
+ // /metrics for hundreds of milliseconds when there are many open fds.
+ // Count the entries directly (readdir only) to avoid the per-entry stat.
+ int64_t count = 0;
+ for (const auto& entry : dict_iter) {
+ (void)entry;
+ ++count;
+ }
process_fd_num_used->set_value(count);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]