From 0ebfef2164ce68b37afdd40cc6c51a8557bac6de Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Tue, 21 Apr 2020 11:57:38 -0300 Subject: [PATCH] Set thread names on proxy/workers Makes debugging which threads are using CPU easier. --- lokimq/proxy.cpp | 8 ++++++++ lokimq/worker.cpp | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/lokimq/proxy.cpp b/lokimq/proxy.cpp index 6b22318..230b4d6 100644 --- a/lokimq/proxy.cpp +++ b/lokimq/proxy.cpp @@ -292,6 +292,14 @@ void LokiMQ::proxy_control_message(std::vector& parts) { void LokiMQ::proxy_loop() { +#if defined(__linux__) || defined(__sun) || defined(__MINGW32__) + pthread_setname_np(pthread_self(), "lmq-proxy"); +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) + pthread_set_name_np(pthread_self(), "lmq-proxy"); +#elif defined(__MACH__) + pthread_setname_np("lmq-proxy"); +#endif + zap_auth.setsockopt(ZMQ_LINGER, 0); zap_auth.bind(ZMQ_ADDR_ZAP); diff --git a/lokimq/worker.cpp b/lokimq/worker.cpp index 3e91fa8..4b4a375 100644 --- a/lokimq/worker.cpp +++ b/lokimq/worker.cpp @@ -7,6 +7,15 @@ namespace lokimq { void LokiMQ::worker_thread(unsigned int index) { std::string worker_id = "w" + std::to_string(index); + +#if defined(__linux__) || defined(__sun) || defined(__MINGW32__) + pthread_setname_np(pthread_self(), worker_id.c_str()); +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) + pthread_set_name_np(pthread_self(), worker_id.c_str()); +#elif defined(__MACH__) + pthread_setname_np(worker_id.c_str()); +#endif + zmq::socket_t sock{context, zmq::socket_type::dealer}; sock.setsockopt(ZMQ_ROUTING_ID, worker_id.data(), worker_id.size()); LMQ_LOG(debug, "New worker thread ", worker_id, " started");