aerospike / aerospike-client-c

Aerospike C Client
Other
98 stars 103 forks source link

Give a name to worker threads #123

Closed bsergean closed 2 years ago

bsergean commented 2 years ago

Inspecting multi-threaded programs with top is made easier when each thread is named.

I think we could made things better by doing that, I see 3 or 4 cases where the client creates a thread (I searched for pthread_create).

  1. as_event_worker
  2. as_shm_tender
  3. as_cluster_tender
  4. (not sure but for libuv and libevent, we could also just use as_uv_worker)
void setThreadName(const std::string & name)
{
#if defined( __APPLE__ )
    //
    // Apple reserves 64 bytes for its thread names
    // Notice that the Apple version of pthread_setname_np
    // does not take a pthread_t argument
    //
    pthread_setname_np(name.substr(0, 63).c_str());
#elif defined( __linux__ )
    //
    // Linux only reserves 16 bytes for its thread names
    // See prctl and PR_SET_NAME property in
    // http://man7.org/linux/man-pages/man2/prctl.2.html
    //
    pthread_setname_np(pthread_self(), name.substr(0, 15).c_str());
#else
    puts("setThreadName: platform not supported"); // remove this, maybe this could be a warning.
#endif
}

Would you accept a PR implementing this ? Any tips on doing this according to your coding style or requirements ?

BrianNichols commented 2 years ago

We will look into setting thread names for the next release.

bsergean commented 2 years ago

Thanks that's great. Not a big deal but a small quality of life improvement, and that sounds rather straightforward.

BrianNichols commented 2 years ago

C client 6.0.0 is released: https://download.aerospike.com/download/client/c/notes.html#6.0.0