Set thread names on proxy/workers

Makes debugging which threads are using CPU easier.
pull/4/head
Jason Rhinelander 2 years ago
parent fc1ea66599
commit 0ebfef2164
  1. 8
      lokimq/proxy.cpp
  2. 9
      lokimq/worker.cpp

@ -292,6 +292,14 @@ void LokiMQ::proxy_control_message(std::vector<zmq::message_t>& 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<int>(ZMQ_LINGER, 0);
zap_auth.bind(ZMQ_ADDR_ZAP);

@ -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");

Loading…
Cancel
Save