From 3cea61392f36d9b2d3086dacf06b3cd7df9d210c Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Wed, 18 Apr 2018 17:25:37 -0700 Subject: [PATCH] include thread-pool priority in thread names Summary: Previously threads were named "rocksdb:bg\", so the first thread in all thread pools would be named "rocksdb:bg0". Users want to be able to distinguish threads used for flush (high-pri) vs regular compaction (low-pri) vs compaction to bottom-level (bottom-pri). So I changed the thread naming convention to include the thread-pool priority. Closes https://github.com/facebook/rocksdb/pull/3702 Differential Revision: D7581415 Pulled By: ajkr fbshipit-source-id: ce04482b6acd956a401ef22dc168b84f76f7d7c1 --- HISTORY.md | 1 + env/env.cc | 14 ++++++++++++++ include/rocksdb/env.h | 2 ++ util/threadpool_imp.cc | 16 ++++++++++------ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 1e7a6bec0..9449970dc 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ ## Unreleased ### Public API Change * Add a BlockBasedTableOption to align uncompressed data blocks on the smaller of block size or page size boundary, to reduce flash reads by avoiding reads spanning 4K pages. +* The background thread naming convention changed (on supporting platforms) to "rocksdb:", e.g., "rocksdb:low0". ### New Features * Introduce TTL for level compaction so that all files older than ttl go through the compaction process to get rid of old data. diff --git a/env/env.cc b/env/env.cc index 56c0bd893..1943f6ad8 100644 --- a/env/env.cc +++ b/env/env.cc @@ -22,6 +22,20 @@ namespace rocksdb { Env::~Env() { } +std::string Env::PriorityToString(Env::Priority priority) { + switch (priority) { + case Env::Priority::BOTTOM: + return "Bottom"; + case Env::Priority::LOW: + return "Low"; + case Env::Priority::HIGH: + return "High"; + case Env::Priority::TOTAL: + assert(false); + } + return "Invalid"; +} + uint64_t Env::GetThreadID() const { std::hash hasher; return hasher(std::this_thread::get_id()); diff --git a/include/rocksdb/env.h b/include/rocksdb/env.h index 866740641..33b366544 100644 --- a/include/rocksdb/env.h +++ b/include/rocksdb/env.h @@ -302,6 +302,8 @@ class Env { // Priority for scheduling job in thread pool enum Priority { BOTTOM, LOW, HIGH, TOTAL }; + static std::string PriorityToString(Priority priority); + // Priority for requesting bytes in rate limiter scheduler enum IOPriority { IO_LOW = 0, diff --git a/util/threadpool_imp.cc b/util/threadpool_imp.cc index 916004820..25ad1a693 100644 --- a/util/threadpool_imp.cc +++ b/util/threadpool_imp.cc @@ -20,11 +20,12 @@ # include #endif +#include #include #include #include #include -#include +#include #include #include @@ -313,11 +314,14 @@ void ThreadPoolImpl::Impl::StartBGThreads() { #if defined(_GNU_SOURCE) && defined(__GLIBC_PREREQ) #if __GLIBC_PREREQ(2, 12) auto th_handle = p_t.native_handle(); - char name_buf[16]; - snprintf(name_buf, sizeof name_buf, "rocksdb:bg%" ROCKSDB_PRIszt, - bgthreads_.size()); - name_buf[sizeof name_buf - 1] = '\0'; - pthread_setname_np(th_handle, name_buf); + std::string thread_priority = Env::PriorityToString(GetThreadPriority()); + std::ostringstream thread_name_stream; + thread_name_stream << "rocksdb:"; + for (char c : thread_priority) { + thread_name_stream << static_cast(tolower(c)); + } + thread_name_stream << bgthreads_.size(); + pthread_setname_np(th_handle, thread_name_stream.str().c_str()); #endif #endif bgthreads_.push_back(std::move(p_t));