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

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 25ac68e2319 [opt](metrics) More precise task execution and wait worker 
time (#48750)
25ac68e2319 is described below

commit 25ac68e231905ddc8ce4f45aebd0cb076a2034b7
Author: zhiqiang <hezhiqi...@selectdb.com>
AuthorDate: Wed Mar 12 00:00:08 2025 +0800

    [opt](metrics) More precise task execution and wait worker time (#48750)
    
    ### What problem does this PR solve?
    
    Add `task_execution_count_total` and `task_wait_worker_count_total =
    nullptr`.
    
    We can calculate avg task execution time and avg wait worker time by:
    ```
    
irate(doris_be_task_wait_worker_time_ns_total{thread_pool_name="Scan_normal"}[$__rate_interval])
    
/(irate(doris_be_task_wait_worker_count_total{thread_pool_name="Scan_normal"}[$__rate_interval])+1)
    ```
    and
    ```
    
irate(doris_be_task_execution_time_ns_total{thread_pool_name="Scan_normal"}[$__rate_interval])
    
/(irate(doris_be_task_execution_count_total{thread_pool_name="Scan_normal"}[$__rate_interval])+1)
    ```
    <img width="996" alt="image"
    
src="https://github.com/user-attachments/assets/37004f23-defd-4811-94ba-7afb588aca84";
    />
---
 be/src/util/threadpool.cpp | 22 ++++++++++++++++------
 be/src/util/threadpool.h   |  6 ++++--
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/be/src/util/threadpool.cpp b/be/src/util/threadpool.cpp
index f0f504b4dc2..4744ae2af1c 100644
--- a/be/src/util/threadpool.cpp
+++ b/be/src/util/threadpool.cpp
@@ -46,8 +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_COUNTER_METRIC_PROTOTYPE_2ARG(task_execution_time_ns_total, 
MetricUnit::NANOSECONDS);
-DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(task_wait_worker_time_ns_total, 
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;
@@ -309,8 +313,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_COUNTER_METRIC_REGISTER(_metric_entity, task_execution_time_ns_total);
-    INT_COUNTER_METRIC_REGISTER(_metric_entity, 
task_wait_worker_time_ns_total);
+    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]() {
@@ -596,7 +602,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_total->increment(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;
@@ -614,7 +622,9 @@ void ThreadPool::dispatch_thread() {
         // with this threadpool, and produce a deadlock.
         task.runnable.reset();
         l.lock();
-        
task_execution_time_ns_total->increment(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 73f0ae33c79..ac1f21efea8 100644
--- a/be/src/util/threadpool.h
+++ b/be/src/util/threadpool.h
@@ -413,8 +413,10 @@ private:
     IntGauge* thread_pool_queue_size = nullptr;
     IntGauge* thread_pool_max_queue_size = nullptr;
     IntGauge* thread_pool_max_threads = nullptr;
-    IntCounter* task_execution_time_ns_total = nullptr;
-    IntCounter* task_wait_worker_time_ns_total = nullptr;
+    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