From 84f81e01003133389cc63f4dc247d8acaff7d910 Mon Sep 17 00:00:00 2001 From: JackyWoo Date: Thu, 17 Aug 2023 17:14:38 +0800 Subject: [PATCH] Add thread name (#83) * add thread name * fix log --- base/daemon/BaseDaemon.cpp | 2 ++ programs/server/Server.cpp | 6 ++---- src/Service/KeeperDispatcher.cpp | 2 +- src/Service/NuRaftStateMachine.cpp | 4 +++- src/Service/RequestAccumulator.cpp | 2 +- src/Service/RequestForwarder.cpp | 4 ++-- src/Service/RequestProcessor.cpp | 2 +- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/base/daemon/BaseDaemon.cpp b/base/daemon/BaseDaemon.cpp index cf87e78495..05bd9f0207 100644 --- a/base/daemon/BaseDaemon.cpp +++ b/base/daemon/BaseDaemon.cpp @@ -152,6 +152,8 @@ class SignalListener : public Poco::Runnable void run() override { + setThreadName("SignalListener"); + char buf[signal_pipe_buf_size]; RK::ReadBufferFromFileDescriptor in(signal_pipe.fds_rw[0], signal_pipe_buf_size, buf); diff --git a/programs/server/Server.cpp b/programs/server/Server.cpp index 85df6584e7..b5b9a28178 100644 --- a/programs/server/Server.cpp +++ b/programs/server/Server.cpp @@ -171,9 +171,8 @@ int Server::main(const std::vector & /*args*/) server = std::make_shared>(timeout, "IO-Acptr"); /// TODO add io thread count to config - static UInt64 handler_thread_id = 0; conn_acceptor = std::make_shared>( - "IO-Hdlr-" + std::to_string(handler_thread_id++), global_context, socket, *server, timeout, cpu_core_size); + "IO-Hdlr", global_context, socket, *server, timeout, cpu_core_size); LOG_INFO(log, "Listening for user connections on {}", socket.address().toString()); }); @@ -195,9 +194,8 @@ int Server::main(const std::vector & /*args*/) forwarding_server = std::make_shared>(timeout, "IO-FwdAcptr"); /// TODO add io thread count to config - static UInt64 handler_thread_id = 0; forwarding_conn_acceptor = std::make_shared>( - "IO-FwdHdlr-" + std::to_string(handler_thread_id++), global_context, socket, *forwarding_server, timeout, cpu_core_size); + "IO-FwdHdlr", global_context, socket, *forwarding_server, timeout, cpu_core_size); LOG_INFO(log, "Listening for forwarding connections on {}", socket.address().toString()); }); diff --git a/src/Service/KeeperDispatcher.cpp b/src/Service/KeeperDispatcher.cpp index cbb29df8fc..214407cd98 100644 --- a/src/Service/KeeperDispatcher.cpp +++ b/src/Service/KeeperDispatcher.cpp @@ -31,7 +31,7 @@ KeeperDispatcher::KeeperDispatcher() void KeeperDispatcher::requestThreadFakeZk(size_t thread_index) { - setThreadName(("ReqDspchr-" + std::to_string(thread_index)).c_str()); + setThreadName(("ReqDspchr#" + std::to_string(thread_index)).c_str()); /// Result of requests batch from previous iteration nuraft::ptr>> prev_result = nullptr; diff --git a/src/Service/NuRaftStateMachine.cpp b/src/Service/NuRaftStateMachine.cpp index ec38c2f04d..428391404e 100644 --- a/src/Service/NuRaftStateMachine.cpp +++ b/src/Service/NuRaftStateMachine.cpp @@ -8,10 +8,11 @@ #include #include #include +#include #include #include #include -#include +#include #ifdef __clang__ @@ -320,6 +321,7 @@ ptr NuRaftStateMachine::createRequestSession(ptr void NuRaftStateMachine::snapThread() { + setThreadName("snapThread"); while (!shutdown_called) { if (snap_task) diff --git a/src/Service/RequestAccumulator.cpp b/src/Service/RequestAccumulator.cpp index 2eb8b30178..445a6d4414 100644 --- a/src/Service/RequestAccumulator.cpp +++ b/src/Service/RequestAccumulator.cpp @@ -13,7 +13,7 @@ void RequestAccumulator::push(const RequestForSession & request_for_session) void RequestAccumulator::run(RunnerId runner_id) { - setThreadName(("ReqAccumu-" + toString(runner_id)).c_str()); + setThreadName(("ReqAccumu#" + toString(runner_id)).c_str()); NuRaftResult result; diff --git a/src/Service/RequestForwarder.cpp b/src/Service/RequestForwarder.cpp index 76b277515c..4fe30236ec 100644 --- a/src/Service/RequestForwarder.cpp +++ b/src/Service/RequestForwarder.cpp @@ -22,7 +22,7 @@ void RequestForwarder::push(const RequestForSession & request_for_session) void RequestForwarder::runSend(RunnerId runner_id) { - setThreadName(("ReqFwdSend-" + toString(runner_id)).c_str()); + setThreadName(("ReqFwdSend#" + toString(runner_id)).c_str()); LOG_DEBUG(log, "Starting forwarding request sending thread."); while (!shutdown_called) @@ -126,7 +126,7 @@ void RequestForwarder::runSend(RunnerId runner_id) void RequestForwarder::runReceive(RunnerId runner_id) { - setThreadName(("ReqFwdRecv-" + toString(runner_id)).c_str()); + setThreadName(("ReqFwdRecv#" + toString(runner_id)).c_str()); LOG_DEBUG(log, "Starting forwarding response receiving thread."); while (!shutdown_called) diff --git a/src/Service/RequestProcessor.cpp b/src/Service/RequestProcessor.cpp index f5c70c57a8..940f81d660 100644 --- a/src/Service/RequestProcessor.cpp +++ b/src/Service/RequestProcessor.cpp @@ -359,7 +359,7 @@ void RequestProcessor::processErrorRequest() log, "Not found error request session {}, xid {} from pending queue. Maybe it is still in the request queue " "and will be processed next time", - session_id, + toHexString(session_id), xid); break; }