Skip to content

Commit 8a6e4d1

Browse files
authored
storage: Use different names for block bg pool (#5867)
ref #5807
1 parent e074cfe commit 8a6e4d1

File tree

4 files changed

+225
-94
lines changed

4 files changed

+225
-94
lines changed

dbms/src/Interpreters/Context.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ BackgroundProcessingPool & Context::initializeBackgroundPool(UInt16 pool_size)
13661366
{
13671367
auto lock = getLock();
13681368
if (!shared->background_pool)
1369-
shared->background_pool = std::make_shared<BackgroundProcessingPool>(pool_size);
1369+
shared->background_pool = std::make_shared<BackgroundProcessingPool>(pool_size, "bg-");
13701370
return *shared->background_pool;
13711371
}
13721372

@@ -1380,7 +1380,7 @@ BackgroundProcessingPool & Context::initializeBlockableBackgroundPool(UInt16 poo
13801380
{
13811381
auto lock = getLock();
13821382
if (!shared->blockable_background_pool)
1383-
shared->blockable_background_pool = std::make_shared<BackgroundProcessingPool>(pool_size);
1383+
shared->blockable_background_pool = std::make_shared<BackgroundProcessingPool>(pool_size, "bg-block-");
13841384
return *shared->blockable_background_pool;
13851385
}
13861386

dbms/src/Storages/BackgroundProcessingPool.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,18 @@ void BackgroundProcessingPool::TaskInfo::wake()
8282
}
8383

8484

85-
BackgroundProcessingPool::BackgroundProcessingPool(int size_)
85+
BackgroundProcessingPool::BackgroundProcessingPool(int size_, std::string thread_prefix_)
8686
: size(size_)
87+
, thread_prefix(thread_prefix_)
8788
, thread_ids_counter(size_)
8889
{
89-
LOG_FMT_INFO(&Poco::Logger::get("BackgroundProcessingPool"), "Create BackgroundProcessingPool with {} threads", size);
90+
LOG_FMT_INFO(Logger::get("BackgroundProcessingPool"), "Create BackgroundProcessingPool, prefix={} n_threads={}", thread_prefix, size);
9091

9192
threads.resize(size);
92-
for (auto & thread : threads)
93-
thread = std::thread([this] { threadFunction(); });
93+
for (size_t i = 0; i < size; ++i)
94+
{
95+
threads[i] = std::thread([this, i] { threadFunction(i); });
96+
}
9497
}
9598

9699

@@ -142,11 +145,10 @@ BackgroundProcessingPool::~BackgroundProcessingPool()
142145
}
143146

144147

145-
void BackgroundProcessingPool::threadFunction()
148+
void BackgroundProcessingPool::threadFunction(size_t thread_idx)
146149
{
147150
{
148-
static std::atomic_uint64_t tid{0};
149-
const auto name = "BkgPool" + std::to_string(tid++);
151+
const auto name = thread_prefix + std::to_string(thread_idx);
150152
setThreadName(name.data());
151153
is_background_thread = true;
152154
addThreadId(getTid());

dbms/src/Storages/BackgroundProcessingPool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class BackgroundProcessingPool
8181
using TaskHandle = std::shared_ptr<TaskInfo>;
8282

8383

84-
explicit BackgroundProcessingPool(int size_);
84+
explicit BackgroundProcessingPool(int size_, std::string thread_prefix_);
8585

8686
size_t getNumberOfThreads() const { return size; }
8787

@@ -109,6 +109,7 @@ class BackgroundProcessingPool
109109
using Threads = std::vector<std::thread>;
110110

111111
const size_t size;
112+
const std::string thread_prefix;
112113
static constexpr double sleep_seconds = 10;
113114
static constexpr double sleep_seconds_random_part = 1.0;
114115

@@ -123,8 +124,7 @@ class BackgroundProcessingPool
123124
std::atomic<bool> shutdown{false};
124125
std::condition_variable wake_event;
125126

126-
127-
void threadFunction();
127+
void threadFunction(size_t thread_idx);
128128
};
129129

130130
using BackgroundProcessingPoolPtr = std::shared_ptr<BackgroundProcessingPool>;

0 commit comments

Comments
 (0)