Merge pull request #7089 from bytedance/set-thread-name
Threaded IO: set thread name for redis-server
This commit is contained in:
commit
85d1d1f870
12
src/bio.c
12
src/bio.c
@ -154,6 +154,18 @@ void *bioProcessBackgroundJobs(void *arg) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case BIO_CLOSE_FILE:
|
||||||
|
redis_set_thread_title("bio_close_file");
|
||||||
|
break;
|
||||||
|
case BIO_AOF_FSYNC:
|
||||||
|
redis_set_thread_title("bio_aof_fsync");
|
||||||
|
break;
|
||||||
|
case BIO_LAZY_FREE:
|
||||||
|
redis_set_thread_title("bio_lazy_free");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Make the thread killable at any time, so that bioKillThreads()
|
/* Make the thread killable at any time, so that bioKillThreads()
|
||||||
* can work reliably. */
|
* can work reliably. */
|
||||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||||
|
12
src/config.h
12
src/config.h
@ -226,4 +226,16 @@ void setproctitle(const char *fmt, ...);
|
|||||||
#define USE_ALIGNED_ACCESS
|
#define USE_ALIGNED_ACCESS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Define for redis_set_thread_title */
|
||||||
|
#ifdef __linux__
|
||||||
|
#define redis_set_thread_title(name) pthread_setname_np(pthread_self(), name)
|
||||||
|
#else
|
||||||
|
#if (defined __NetBSD__ || defined __FreeBSD__ || defined __OpenBSD__)
|
||||||
|
#include <pthread_np.h>
|
||||||
|
#define redis_set_thread_title(name) pthread_set_name_np(pthread_self(), name)
|
||||||
|
#else
|
||||||
|
#define redis_set_thread_title(name)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2821,6 +2821,10 @@ void *IOThreadMain(void *myid) {
|
|||||||
/* The ID is the thread number (from 0 to server.iothreads_num-1), and is
|
/* The ID is the thread number (from 0 to server.iothreads_num-1), and is
|
||||||
* used by the thread to just manipulate a single sub-array of clients. */
|
* used by the thread to just manipulate a single sub-array of clients. */
|
||||||
long id = (unsigned long)myid;
|
long id = (unsigned long)myid;
|
||||||
|
char thdname[16];
|
||||||
|
|
||||||
|
snprintf(thdname, sizeof(thdname), "io_thd_%ld", id);
|
||||||
|
redis_set_thread_title(thdname);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
/* Wait for start */
|
/* Wait for start */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user