This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new 314d79760e4 branch-3.0: [opt](metrics) More precise task execution and 
wait worker time #48750 (#51319)
314d79760e4 is described below

commit 314d79760e40756e599cdc951d9ed87dbce6211e
Author: zhiqiang <hezhiqi...@selectdb.com>
AuthorDate: Wed Jun 11 10:36:21 2025 +0800

    branch-3.0: [opt](metrics) More precise task execution and wait worker time 
#48750 (#51319)
    
    cherry pick from #48750
---
 be/src/util/threadpool.cpp | 28 ++++++++++++++++------------
 be/src/util/threadpool.h   |  9 ++++-----
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/be/src/util/threadpool.cpp b/be/src/util/threadpool.cpp
index a5220be08a8..7bd656a81b7 100644
--- a/be/src/util/threadpool.cpp
+++ b/be/src/util/threadpool.cpp
@@ -46,10 +46,12 @@ DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(thread_pool_queue_size, 
MetricUnit::NOUNIT);
 DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(thread_pool_max_queue_size, 
MetricUnit::NOUNIT);
 DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(thread_pool_max_threads, 
MetricUnit::NOUNIT);
 DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(thread_pool_submit_failed, 
MetricUnit::NOUNIT);
-DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(task_execution_time_ns_avg_in_last_1000_times,
-                                   MetricUnit::NANOSECONDS);
-DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(task_wait_worker_ns_avg_in_last_1000_times,
-                                   MetricUnit::NANOSECONDS);
+DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(thread_pool_task_execution_time_ns_total,
+                                     MetricUnit::NANOSECONDS);
+DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(thread_pool_task_execution_count_total, 
MetricUnit::NOUNIT);
+DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(thread_pool_task_wait_worker_time_ns_total,
+                                     MetricUnit::NANOSECONDS);
+DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(thread_pool_task_wait_worker_count_total, 
MetricUnit::NOUNIT);
 using namespace ErrorCode;
 
 using std::string;
@@ -297,8 +299,10 @@ Status ThreadPool::init() {
     INT_GAUGE_METRIC_REGISTER(_metric_entity, thread_pool_max_threads);
     INT_GAUGE_METRIC_REGISTER(_metric_entity, thread_pool_queue_size);
     INT_GAUGE_METRIC_REGISTER(_metric_entity, thread_pool_max_queue_size);
-    INT_GAUGE_METRIC_REGISTER(_metric_entity, 
task_execution_time_ns_avg_in_last_1000_times);
-    INT_GAUGE_METRIC_REGISTER(_metric_entity, 
task_wait_worker_ns_avg_in_last_1000_times);
+    INT_COUNTER_METRIC_REGISTER(_metric_entity, 
thread_pool_task_execution_time_ns_total);
+    INT_COUNTER_METRIC_REGISTER(_metric_entity, 
thread_pool_task_execution_count_total);
+    INT_COUNTER_METRIC_REGISTER(_metric_entity, 
thread_pool_task_wait_worker_time_ns_total);
+    INT_COUNTER_METRIC_REGISTER(_metric_entity, 
thread_pool_task_wait_worker_count_total);
     INT_COUNTER_METRIC_REGISTER(_metric_entity, thread_pool_submit_failed);
 
     _metric_entity->register_hook("update", [this]() {
@@ -313,10 +317,6 @@ Status ThreadPool::init() {
         thread_pool_queue_size->set_value(get_queue_size());
         thread_pool_max_queue_size->set_value(get_max_queue_size());
         thread_pool_max_threads->set_value(max_threads());
-        task_execution_time_ns_avg_in_last_1000_times->set_value(
-                _task_execution_time_ns_statistic.mean());
-        task_wait_worker_ns_avg_in_last_1000_times->set_value(
-                _task_wait_worker_time_ns_statistic.mean());
     });
     return Status::OK();
 }
@@ -588,7 +588,9 @@ void ThreadPool::dispatch_thread() {
         DCHECK_EQ(ThreadPoolToken::State::RUNNING, token->state());
         DCHECK(!token->_entries.empty());
         Task task = std::move(token->_entries.front());
-        
_task_wait_worker_time_ns_statistic.add(task.submit_time_wather.elapsed_time());
+        thread_pool_task_wait_worker_time_ns_total->increment(
+                task.submit_time_wather.elapsed_time());
+        thread_pool_task_wait_worker_count_total->increment(1);
         token->_entries.pop_front();
         token->_active_threads++;
         --_total_queued_tasks;
@@ -606,7 +608,9 @@ void ThreadPool::dispatch_thread() {
         // with this threadpool, and produce a deadlock.
         task.runnable.reset();
         l.lock();
-        
_task_execution_time_ns_statistic.add(task_execution_time_watch.elapsed_time());
+        thread_pool_task_execution_time_ns_total->increment(
+                task_execution_time_watch.elapsed_time());
+        thread_pool_task_execution_count_total->increment(1);
         // Possible states:
         // 1. The token was shut down while we ran its task. Transition to 
QUIESCED.
         // 2. The token has no more queued tasks. Transition back to IDLE.
diff --git a/be/src/util/threadpool.h b/be/src/util/threadpool.h
index 716a59a3787..de274e54af1 100644
--- a/be/src/util/threadpool.h
+++ b/be/src/util/threadpool.h
@@ -411,11 +411,10 @@ private:
     IntGauge* thread_pool_queue_size = nullptr;
     IntGauge* thread_pool_max_queue_size = nullptr;
     IntGauge* thread_pool_max_threads = nullptr;
-    IntGauge* task_execution_time_ns_avg_in_last_1000_times = nullptr;
-    IntGauge* task_wait_worker_ns_avg_in_last_1000_times = nullptr;
-
-    IntervalHistogramStat<int64_t> _task_execution_time_ns_statistic {1000};
-    IntervalHistogramStat<int64_t> _task_wait_worker_time_ns_statistic {1000};
+    IntCounter* thread_pool_task_execution_time_ns_total = nullptr;
+    IntCounter* thread_pool_task_execution_count_total = nullptr;
+    IntCounter* thread_pool_task_wait_worker_time_ns_total = nullptr;
+    IntCounter* thread_pool_task_wait_worker_count_total = nullptr;
 
     IntCounter* thread_pool_submit_failed = nullptr;
 };


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to