diff --git a/src/Core/BackgroundSchedulePool.cpp b/src/Core/BackgroundSchedulePool.cpp index bd2e5e91dfa..b92f7f0ae6e 100644 --- a/src/Core/BackgroundSchedulePool.cpp +++ b/src/Core/BackgroundSchedulePool.cpp @@ -148,12 +148,13 @@ Coordination::WatchCallback BackgroundSchedulePoolTaskInfo::getWatchCallback() } -BackgroundSchedulePool::BackgroundSchedulePool(size_t size_, CurrentMetrics::Metric tasks_metric_, CurrentMetrics::Metric memory_metric_) +BackgroundSchedulePool::BackgroundSchedulePool(size_t size_, CurrentMetrics::Metric tasks_metric_, CurrentMetrics::Metric memory_metric_, const char *thread_name_) : size(size_) , tasks_metric(tasks_metric_) , memory_metric(memory_metric_) + , thread_name(thread_name_) { - LOG_INFO(&Logger::get("BackgroundSchedulePool"), "Create BackgroundSchedulePool with " << size << " threads"); + LOG_INFO(&Logger::get("BackgroundSchedulePool/" + thread_name), "Create BackgroundSchedulePool with " << size << " threads"); threads.resize(size); for (auto & thread : threads) @@ -176,7 +177,7 @@ BackgroundSchedulePool::~BackgroundSchedulePool() queue.wakeUpAll(); delayed_thread.join(); - LOG_TRACE(&Logger::get("BackgroundSchedulePool"), "Waiting for threads to finish."); + LOG_TRACE(&Logger::get("BackgroundSchedulePool/" + thread_name), "Waiting for threads to finish."); for (auto & thread : threads) thread.join(); } @@ -242,7 +243,7 @@ void BackgroundSchedulePool::attachToThreadGroup() void BackgroundSchedulePool::threadFunction() { - setThreadName("BackgrSchedPool"); + setThreadName(thread_name.c_str()); attachToThreadGroup(); SCOPE_EXIT({ CurrentThread::detachQueryIfNotDetached(); }); @@ -262,7 +263,7 @@ void BackgroundSchedulePool::threadFunction() void BackgroundSchedulePool::delayExecutionThreadFunction() { - setThreadName("BckSchPoolDelay"); + setThreadName((thread_name + "/D").c_str()); attachToThreadGroup(); SCOPE_EXIT({ CurrentThread::detachQueryIfNotDetached(); }); diff --git a/src/Core/BackgroundSchedulePool.h b/src/Core/BackgroundSchedulePool.h index 712be1e47b4..65e163a5320 100644 --- a/src/Core/BackgroundSchedulePool.h +++ b/src/Core/BackgroundSchedulePool.h @@ -50,7 +50,8 @@ public: size_t getNumberOfThreads() const { return size; } - BackgroundSchedulePool(size_t size_, CurrentMetrics::Metric tasks_metric_, CurrentMetrics::Metric memory_metric_); + /// thread_name_ cannot be longer then 13 bytes (2 bytes is reserved for "/D" suffix for delayExecutionThreadFunction()) + BackgroundSchedulePool(size_t size_, CurrentMetrics::Metric tasks_metric_, CurrentMetrics::Metric memory_metric_, const char *thread_name_); ~BackgroundSchedulePool(); private: @@ -85,6 +86,7 @@ private: CurrentMetrics::Metric tasks_metric; CurrentMetrics::Metric memory_metric; + std::string thread_name; void attachToThreadGroup(); }; diff --git a/src/Interpreters/Context.cpp b/src/Interpreters/Context.cpp index dd6f0e04bfa..48580574a8e 100644 --- a/src/Interpreters/Context.cpp +++ b/src/Interpreters/Context.cpp @@ -1363,7 +1363,8 @@ BackgroundSchedulePool & Context::getBufferFlushSchedulePool() shared->buffer_flush_schedule_pool.emplace( settings.background_buffer_flush_schedule_pool_size, CurrentMetrics::BackgroundBufferFlushSchedulePoolTask, - CurrentMetrics::MemoryTrackingInBackgroundBufferFlushSchedulePool); + CurrentMetrics::MemoryTrackingInBackgroundBufferFlushSchedulePool, + "BgBufSchPool"); return *shared->buffer_flush_schedule_pool; } @@ -1374,7 +1375,8 @@ BackgroundSchedulePool & Context::getSchedulePool() shared->schedule_pool.emplace( settings.background_schedule_pool_size, CurrentMetrics::BackgroundSchedulePoolTask, - CurrentMetrics::MemoryTrackingInBackgroundSchedulePool); + CurrentMetrics::MemoryTrackingInBackgroundSchedulePool, + "BgSchPool"); return *shared->schedule_pool; } @@ -1385,7 +1387,8 @@ BackgroundSchedulePool & Context::getDistributedSchedulePool() shared->distributed_schedule_pool.emplace( settings.background_distributed_schedule_pool_size, CurrentMetrics::BackgroundDistributedSchedulePoolTask, - CurrentMetrics::MemoryTrackingInBackgroundDistributedSchedulePool); + CurrentMetrics::MemoryTrackingInBackgroundDistributedSchedulePool, + "BgDistSchPool"); return *shared->distributed_schedule_pool; }