enhance: Make segcore thread name set correctly (#42497)

Previous PR: #42017 did not work due to following updated points by this
PR:

- Initialize the `name_map`, which not touched at all before
- Trim the thread name under 15 characters to fit syscall limit

---------

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2025-06-06 16:26:32 +08:00 committed by GitHub
parent cc5ac1c220
commit b50c4a7973
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View File

@ -14,12 +14,12 @@
// //
#include "ThreadPools.h" #include "ThreadPools.h"
#include <mutex>
namespace milvus { namespace milvus {
std::map<ThreadPoolPriority, std::unique_ptr<ThreadPool>> std::map<ThreadPoolPriority, std::unique_ptr<ThreadPool>>
ThreadPools::thread_pool_map; ThreadPools::thread_pool_map;
std::map<ThreadPoolPriority, std::string> ThreadPools::name_map;
std::shared_mutex ThreadPools::mutex_; std::shared_mutex ThreadPools::mutex_;
void void
@ -50,7 +50,7 @@ ThreadPools::GetThreadPool(milvus::ThreadPoolPriority priority) {
coefficient = LOW_PRIORITY_THREAD_CORE_COEFFICIENT; coefficient = LOW_PRIORITY_THREAD_CORE_COEFFICIENT;
break; break;
} }
std::string name = name_map[priority]; std::string name = name_map()[priority];
auto result = thread_pool_map.emplace( auto result = thread_pool_map.emplace(
priority, std::make_unique<ThreadPool>(coefficient, name)); priority, std::make_unique<ThreadPool>(coefficient, name));
return *(result.first->second); return *(result.first->second);

View File

@ -42,15 +42,21 @@ class ThreadPools {
private: private:
ThreadPools() { ThreadPools() {
name_map[HIGH] = "high_priority_thread_pool";
name_map[MIDDLE] = "middle_priority_thread_pool";
name_map[LOW] = "low_priority_thread_pool";
} }
void void
ShutDown(); ShutDown();
static std::map<ThreadPoolPriority, std::string>
name_map() {
static std::map<ThreadPoolPriority, std::string> name_map = {
{HIGH, "HIGH_SEGC_POOL"},
{MIDDLE, "MIDD_SEGC_POOL"},
{LOW, "LOW_SEGC_POOL"}};
return name_map;
}
static std::map<ThreadPoolPriority, std::unique_ptr<ThreadPool>> static std::map<ThreadPoolPriority, std::unique_ptr<ThreadPool>>
thread_pool_map; thread_pool_map;
static std::map<ThreadPoolPriority, std::string> name_map;
static std::shared_mutex mutex_; static std::shared_mutex mutex_;
}; };