Skip to content

Commit

Permalink
Add thread name (#83)
Browse files Browse the repository at this point in the history
* add thread name

* fix log
  • Loading branch information
JackyWoo authored Aug 17, 2023
1 parent 3438d13 commit 84f81e0
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions base/daemon/BaseDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 2 additions & 4 deletions programs/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,8 @@ int Server::main(const std::vector<std::string> & /*args*/)
server = std::make_shared<SvsSocketReactor<SocketReactor>>(timeout, "IO-Acptr");

/// TODO add io thread count to config
static UInt64 handler_thread_id = 0;
conn_acceptor = std::make_shared<SvsSocketAcceptor<ConnectionHandler, SocketReactor>>(
"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());
});

Expand All @@ -195,9 +194,8 @@ int Server::main(const std::vector<std::string> & /*args*/)
forwarding_server = std::make_shared<SvsSocketReactor<SocketReactor>>(timeout, "IO-FwdAcptr");

/// TODO add io thread count to config
static UInt64 handler_thread_id = 0;
forwarding_conn_acceptor = std::make_shared<SvsSocketAcceptor<ForwardingConnectionHandler, SocketReactor>>(
"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());
});

Expand Down
2 changes: 1 addition & 1 deletion src/Service/KeeperDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nuraft::cmd_result<nuraft::ptr<nuraft::buffer>>> prev_result = nullptr;
Expand Down
4 changes: 3 additions & 1 deletion src/Service/NuRaftStateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include <Service/ReadBufferFromNuraftBuffer.h>
#include <Service/RequestProcessor.h>
#include <Service/WriteBufferFromNuraftBuffer.h>
#include <Service/ThreadSafeQueue.h>
#include <ZooKeeper/ZooKeeperIO.h>
#include <Poco/File.h>
#include <Common/Stopwatch.h>
#include <Service/ThreadSafeQueue.h>
#include <Common/setThreadName.h>


#ifdef __clang__
Expand Down Expand Up @@ -320,6 +321,7 @@ ptr<KeeperStore::RequestForSession> NuRaftStateMachine::createRequestSession(ptr

void NuRaftStateMachine::snapThread()
{
setThreadName("snapThread");
while (!shutdown_called)
{
if (snap_task)
Expand Down
2 changes: 1 addition & 1 deletion src/Service/RequestAccumulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/Service/RequestForwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Service/RequestProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 84f81e0

Please sign in to comment.