Name grpc threads

61 views
Skip to first unread message

daniel....@gmail.com

unread,
Dec 16, 2019, 8:16:48 AM12/16/19
to grpc.io
Hello!

Is it possible to somehow name the threads that are spawned by grpc? Would be nice if I could set the thread name for logging purposes in all my server methods.
Right now if I try to log the thread name of some internal code that I call in the server rpcs, it will have some random id from a spawned grpc threadpool thread.

All the best
Daniel

Christopher Warrington - MSFT

unread,
Dec 17, 2019, 2:53:54 AM12/17/19
to grpc.io
On Monday, December 16, 2019 at 5:16:48 AM UTC-8, Daniel wrote:

> Is it possible to somehow name the threads that are spawned by grpc?

Which language are you using? Which implementation of gRPC are you using?

--
Christopher Warrington
Microsoft Corp.

daniel....@gmail.com

unread,
Dec 17, 2019, 7:47:56 AM12/17/19
to grpc.io
I'm using c++ and version 1.22.1.

Yang Gao

unread,
Dec 30, 2019, 4:24:48 PM12/30/19
to grpc.io
It is not clear which thread you are talking about and your platform.

gRPC core does set thread names if applicable. For example the sync server will set its threads with name "grpcpp_sync_server" in thread_manager.cc. For linux, the name is set to the pthread if GPR_LINUX_PTHREAD_NAME macro is set. 
If you use the gpr_log functions the current thread id will be logged, which is a way for you to tell which thread the log is generated from.

If you really want to set some thread name of your own, I guess you can (for linux) maybe use pthread_setname_np in your method handler? You can use gRPC's thd_posix.cc as an example.
Reply all
Reply to author
Forward
0 new messages