summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2020-04-20 11:54:25 +0200
committerGitHub <noreply@github.com>2020-04-20 11:54:25 +0200
commit85d1d1f8700a050ef3178a2d5f5757f9aa77476b (patch)
tree23c46e3971d1435b571798f67db6707ef5374d31
parent23219392184ef605cab26323a94ae031273bc6e7 (diff)
parent5010da6ab068cab4ee19591ebaf7112b9ec5f375 (diff)
downloadredis-85d1d1f8700a050ef3178a2d5f5757f9aa77476b.tar.gz
Merge pull request #7089 from bytedance/set-thread-name
Threaded IO: set thread name for redis-server
-rw-r--r--src/bio.c12
-rw-r--r--src/config.h12
-rw-r--r--src/networking.c4
3 files changed, 28 insertions, 0 deletions
diff --git a/src/bio.c b/src/bio.c
index 2af684570..0662c8c4c 100644
--- a/src/bio.c
+++ b/src/bio.c
@@ -154,6 +154,18 @@ void *bioProcessBackgroundJobs(void *arg) {
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()
* can work reliably. */
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
diff --git a/src/config.h b/src/config.h
index efa9d11f2..82dc201d3 100644
--- a/src/config.h
+++ b/src/config.h
@@ -226,4 +226,16 @@ void setproctitle(const char *fmt, ...);
#define USE_ALIGNED_ACCESS
#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
diff --git a/src/networking.c b/src/networking.c
index 8f3d79170..1f5d0bd5d 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -2821,6 +2821,10 @@ void *IOThreadMain(void *myid) {
/* 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. */
long id = (unsigned long)myid;
+ char thdname[16];
+
+ snprintf(thdname, sizeof(thdname), "io_thd_%ld", id);
+ redis_set_thread_title(thdname);
while(1) {
/* Wait for start */