include thread-pool priority in thread names

Summary:
Previously threads were named "rocksdb:bg\<index in thread pool\>", 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
main
Andrew Kryczka 7 years ago committed by Facebook Github Bot
parent 6d06be22c0
commit 3cea61392f
  1. 1
      HISTORY.md
  2. 14
      env/env.cc
  3. 2
      include/rocksdb/env.h
  4. 16
      util/threadpool_imp.cc

@ -2,6 +2,7 @@
## Unreleased ## Unreleased
### Public API Change ### 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. * 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:<thread pool priority><thread number>", e.g., "rocksdb:low0".
### New Features ### 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. * Introduce TTL for level compaction so that all files older than ttl go through the compaction process to get rid of old data.

14
env/env.cc vendored

@ -22,6 +22,20 @@ namespace rocksdb {
Env::~Env() { 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 { uint64_t Env::GetThreadID() const {
std::hash<std::thread::id> hasher; std::hash<std::thread::id> hasher;
return hasher(std::this_thread::get_id()); return hasher(std::this_thread::get_id());

@ -302,6 +302,8 @@ class Env {
// Priority for scheduling job in thread pool // Priority for scheduling job in thread pool
enum Priority { BOTTOM, LOW, HIGH, TOTAL }; enum Priority { BOTTOM, LOW, HIGH, TOTAL };
static std::string PriorityToString(Priority priority);
// Priority for requesting bytes in rate limiter scheduler // Priority for requesting bytes in rate limiter scheduler
enum IOPriority { enum IOPriority {
IO_LOW = 0, IO_LOW = 0,

@ -20,11 +20,12 @@
# include <sys/syscall.h> # include <sys/syscall.h>
#endif #endif
#include <stdlib.h>
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include <condition_variable> #include <condition_variable>
#include <mutex> #include <mutex>
#include <stdlib.h> #include <sstream>
#include <thread> #include <thread>
#include <vector> #include <vector>
@ -313,11 +314,14 @@ void ThreadPoolImpl::Impl::StartBGThreads() {
#if defined(_GNU_SOURCE) && defined(__GLIBC_PREREQ) #if defined(_GNU_SOURCE) && defined(__GLIBC_PREREQ)
#if __GLIBC_PREREQ(2, 12) #if __GLIBC_PREREQ(2, 12)
auto th_handle = p_t.native_handle(); auto th_handle = p_t.native_handle();
char name_buf[16]; std::string thread_priority = Env::PriorityToString(GetThreadPriority());
snprintf(name_buf, sizeof name_buf, "rocksdb:bg%" ROCKSDB_PRIszt, std::ostringstream thread_name_stream;
bgthreads_.size()); thread_name_stream << "rocksdb:";
name_buf[sizeof name_buf - 1] = '\0'; for (char c : thread_priority) {
pthread_setname_np(th_handle, name_buf); thread_name_stream << static_cast<char>(tolower(c));
}
thread_name_stream << bgthreads_.size();
pthread_setname_np(th_handle, thread_name_stream.str().c_str());
#endif #endif
#endif #endif
bgthreads_.push_back(std::move(p_t)); bgthreads_.push_back(std::move(p_t));

Loading…
Cancel
Save