You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by ji...@apache.org on 2023/02/27 19:12:01 UTC
[brpc] branch master updated: naming timer sampling and worker threads (#2136)
This is an automated email from the ASF dual-hosted git repository.
jiashunzhu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new ef469983 naming timer sampling and worker threads (#2136)
ef469983 is described below
commit ef46998312611b08d5d5a153f8e9579ba387d9ea
Author: DongSheng He <eh...@qq.com>
AuthorDate: Tue Feb 28 03:11:50 2023 +0800
naming timer sampling and worker threads (#2136)
* naming timer sampling and worker threads
* naming colloctor and varaiable
* naming usercode backup thread
---------
Co-authored-by: DongSheng He <hd...@dipeak.com>
---
src/brpc/details/usercode_backup_pool.cpp | 2 ++
src/bthread/task_control.cpp | 6 ++++++
src/bthread/task_control.h | 1 +
src/bthread/timer_thread.cpp | 2 ++
src/bvar/collector.cpp | 3 +++
src/bvar/detail/sampler.cpp | 2 ++
src/bvar/variable.cpp | 2 ++
7 files changed, 18 insertions(+)
diff --git a/src/brpc/details/usercode_backup_pool.cpp b/src/brpc/details/usercode_backup_pool.cpp
index 53a1541d..489def45 100644
--- a/src/brpc/details/usercode_backup_pool.cpp
+++ b/src/brpc/details/usercode_backup_pool.cpp
@@ -20,6 +20,7 @@
#include <vector>
#include <gflags/gflags.h>
#include "butil/scoped_lock.h"
+#include "butil/threading/platform_thread.h"
#ifdef BAIDU_INTERNAL
#include "butil/comlog_sink.h"
#endif
@@ -91,6 +92,7 @@ UserCodeBackupPool::UserCodeBackupPool()
}
static void* UserCodeRunner(void* args) {
+ butil::PlatformThread::SetName("brpc_user_code_runner");
static_cast<UserCodeBackupPool*>(args)->UserCodeRunningLoop();
return NULL;
}
diff --git a/src/bthread/task_control.cpp b/src/bthread/task_control.cpp
index fce24459..15f1d7b6 100644
--- a/src/bthread/task_control.cpp
+++ b/src/bthread/task_control.cpp
@@ -22,6 +22,7 @@
#include "butil/scoped_lock.h" // BAIDU_SCOPED_LOCK
#include "butil/errno.h" // berror
#include "butil/logging.h"
+#include "butil/threading/platform_thread.h"
#include "butil/third_party/murmurhash3/murmurhash3.h"
#include "bthread/sys_futex.h" // futex_wake_private
#include "bthread/interrupt_pthread.h"
@@ -68,6 +69,10 @@ void* TaskControl::worker_thread(void* arg) {
LOG(ERROR) << "Fail to create TaskGroup in pthread=" << pthread_self();
return NULL;
}
+ std::string worker_thread_name = butil::string_printf(
+ "brpc_worker:%d",
+ c->_next_worker_id.fetch_add(1, butil::memory_order_relaxed));
+ butil::PlatformThread::SetName(worker_thread_name.c_str());
BT_VLOG << "Created worker=" << pthread_self()
<< " bthread=" << g->main_tid();
@@ -126,6 +131,7 @@ TaskControl::TaskControl()
, _groups((TaskGroup**)calloc(BTHREAD_MAX_CONCURRENCY, sizeof(TaskGroup*)))
, _stop(false)
, _concurrency(0)
+ , _next_worker_id(0)
, _nworkers("bthread_worker_count")
, _pending_time(NULL)
// Delay exposure of following two vars because they rely on TC which
diff --git a/src/bthread/task_control.h b/src/bthread/task_control.h
index 9596d032..e318c265 100644
--- a/src/bthread/task_control.h
+++ b/src/bthread/task_control.h
@@ -98,6 +98,7 @@ private:
bool _stop;
butil::atomic<int> _concurrency;
std::vector<pthread_t> _workers;
+ butil::atomic<int> _next_worker_id;
bvar::Adder<int64_t> _nworkers;
butil::Mutex _pending_time_mutex;
diff --git a/src/bthread/timer_thread.cpp b/src/bthread/timer_thread.cpp
index cdfca646..238a396f 100644
--- a/src/bthread/timer_thread.cpp
+++ b/src/bthread/timer_thread.cpp
@@ -23,6 +23,7 @@
#include "butil/logging.h"
#include "butil/third_party/murmurhash3/murmurhash3.h" // fmix64
#include "butil/resource_pool.h"
+#include "butil/threading/platform_thread.h"
#include "bvar/bvar.h"
#include "bthread/sys_futex.h"
#include "bthread/timer_thread.h"
@@ -117,6 +118,7 @@ inline bool task_greater(const TimerThread::Task* a, const TimerThread::Task* b)
}
void* TimerThread::run_this(void* arg) {
+ butil::PlatformThread::SetName("brpc_timer");
static_cast<TimerThread*>(arg)->run();
return NULL;
}
diff --git a/src/bvar/collector.cpp b/src/bvar/collector.cpp
index c7844c1f..d708bd52 100644
--- a/src/bvar/collector.cpp
+++ b/src/bvar/collector.cpp
@@ -20,6 +20,7 @@
#include <map>
#include <gflags/gflags.h>
#include "butil/memory/singleton_on_pthread_once.h"
+#include "butil/threading/platform_thread.h"
#include "bvar/bvar.h"
#include "bvar/collector.h"
@@ -76,11 +77,13 @@ private:
int64_t interval_us);
static void* run_grab_thread(void* arg) {
+ butil::PlatformThread::SetName("bvar_collector_grabber");
static_cast<Collector*>(arg)->grab_thread();
return NULL;
}
static void* run_dump_thread(void* arg) {
+ butil::PlatformThread::SetName("bvar_collector_dumper");
static_cast<Collector*>(arg)->dump_thread();
return NULL;
}
diff --git a/src/bvar/detail/sampler.cpp b/src/bvar/detail/sampler.cpp
index 1d398ba9..ea826120 100644
--- a/src/bvar/detail/sampler.cpp
+++ b/src/bvar/detail/sampler.cpp
@@ -18,6 +18,7 @@
// Date: Tue Jul 28 18:14:40 CST 2015
#include <gflags/gflags.h>
+#include "butil/threading/platform_thread.h"
#include "butil/time.h"
#include "butil/memory/singleton_on_pthread_once.h"
#include "bvar/reducer.h"
@@ -108,6 +109,7 @@ private:
void run();
static void* sampling_thread(void* arg) {
+ butil::PlatformThread::SetName("bvar_sampler");
static_cast<SamplerCollector*>(arg)->run();
return NULL;
}
diff --git a/src/bvar/variable.cpp b/src/bvar/variable.cpp
index 1f9da3a1..630d2af2 100644
--- a/src/bvar/variable.cpp
+++ b/src/bvar/variable.cpp
@@ -29,6 +29,7 @@
#include "butil/errno.h" // berror
#include "butil/time.h" // milliseconds_from_now
#include "butil/file_util.h" // butil::FilePath
+#include "butil/threading/platform_thread.h"
#include "bvar/gflag.h"
#include "bvar/variable.h"
#include "bvar/mvariable.h"
@@ -728,6 +729,7 @@ static GFlag s_gflag_bvar_dump_interval("bvar_dump_interval");
static void* dumping_thread(void*) {
// NOTE: this variable was declared as static <= r34381, which was
// destructed when program exits and caused coredumps.
+ butil::PlatformThread::SetName("bvar_dumper");
const std::string command_name = read_command_name();
std::string last_filename;
std::string mbvar_last_filename;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org