From 7cbfee68648a419f6465af3c8d8ca4baa2e9fb70 Mon Sep 17 00:00:00 2001 From: Mikhail Filimonov Date: Mon, 22 Jan 2024 18:25:12 +0100 Subject: [PATCH] addind some metrics to worker --- src/Common/ProfileEvents.cpp | 6 ++++++ src/Common/ThreadPool.cpp | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Common/ProfileEvents.cpp b/src/Common/ProfileEvents.cpp index 0ae5eb37ab0e..23d274d8137b 100644 --- a/src/Common/ProfileEvents.cpp +++ b/src/Common/ProfileEvents.cpp @@ -80,6 +80,9 @@ M(GlobalThreadPoolJobEmplacementMicroseconds, "") \ M(GlobalThreadPoolCondVarWaitingMicroseconds, "") \ M(GlobalThreadPoolJobsCounter, "") \ + M(GlobalThreadPoolWorkerLoops, "") \ + M(GlobalThreadPoolWorkerLockWaitMicroseconds, "") \ + M(GlobalThreadPoolWorkerLockHoldingMicroseconds, "") \ \ M(LocalThreadPoolExpansions, "Counts the total number of times threads were borrowed from the global thread pool to expand local thread pools.") \ M(LocalThreadPoolShrinks, "Counts the total number of times threads were returned to the global thread pool from local thread pools.") \ @@ -89,6 +92,9 @@ M(LocalThreadPoolJobEmplacementMicroseconds, "") \ M(LocalThreadPoolCondVarWaitingMicroseconds, "") \ M(LocalThreadPoolJobsCounter, "") \ + M(LocalThreadPoolWorkerLoops, "") \ + M(LocalThreadPoolWorkerLockWaitMicroseconds, "") \ + M(LocalThreadPoolWorkerLockHoldingMicroseconds, "") \ \ M(DiskS3GetRequestThrottlerCount, "Number of DiskS3 GET and SELECT requests passed through throttler.") \ M(DiskS3GetRequestThrottlerSleepMicroseconds, "Total time a query was sleeping to conform DiskS3 GET and SELECT request throttling.") \ diff --git a/src/Common/ThreadPool.cpp b/src/Common/ThreadPool.cpp index e17bf2e2b7e1..a6cfec9521e7 100644 --- a/src/Common/ThreadPool.cpp +++ b/src/Common/ThreadPool.cpp @@ -39,6 +39,10 @@ namespace ProfileEvents extern const Event GlobalThreadPoolJobEmplacementMicroseconds; extern const Event GlobalThreadPoolJobsCounter; extern const Event GlobalThreadPoolCondVarWaitingMicroseconds; + extern const Event GlobalThreadPoolWorkerLoops; + extern const Event GlobalThreadPoolWorkerLockWaitMicroseconds; + extern const Event GlobalThreadPoolWorkerLockHoldingMicroseconds; + extern const Event LocalThreadPoolExpansions; extern const Event LocalThreadPoolShrinks; @@ -48,6 +52,10 @@ namespace ProfileEvents extern const Event LocalThreadPoolJobEmplacementMicroseconds; extern const Event LocalThreadPoolJobsCounter; extern const Event LocalThreadPoolCondVarWaitingMicroseconds; + extern const Event LocalThreadPoolWorkerLoops; + extern const Event LocalThreadPoolWorkerLockWaitMicroseconds; + extern const Event LocalThreadPoolWorkerLockHoldingMicroseconds; + } class JobWithPriority @@ -463,11 +471,20 @@ void ThreadPoolImpl::worker(typename std::list::iterator thread_ /// This is inside the loop to also reset previous thread names set inside the jobs. setThreadName(DEFAULT_THREAD_NAME); + ProfileEvents::increment( std::is_same_v ? ProfileEvents::GlobalThreadPoolWorkerLoops : ProfileEvents::LocalThreadPoolWorkerLoops); + + /// Get a job from the queue. std::optional job_data; { + Stopwatch watch; std::unique_lock lock(mutex); + ProfileEvents::increment( + std::is_same_v ? ProfileEvents::GlobalThreadPoolWorkerLockWaitMicroseconds : ProfileEvents::LocalThreadPoolWorkerLockWaitMicroseconds, + watch.elapsedMicroseconds()); + + watch.restart(); // Finish with previous job if any if (job_is_done) @@ -518,6 +535,10 @@ void ThreadPoolImpl::worker(typename std::list::iterator thread_ job_is_done = true; continue; } + + ProfileEvents::increment( + std::is_same_v ? ProfileEvents::GlobalThreadPoolWorkerLockHoldingMicroseconds : ProfileEvents::LocalThreadPoolWorkerLockHoldingMicroseconds, + watch.elapsedMicroseconds()); } ALLOW_ALLOCATIONS_IN_SCOPE;