Configure thread names for buffer/distributed schedule pools

This commit is contained in:
Azat Khuzhin 2020-04-23 03:14:58 +03:00
parent d854049d21
commit 4f5ec14f27
3 changed files with 15 additions and 9 deletions

View File

@ -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(); });

View File

@ -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();
};

View File

@ -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;
}