diff --git a/.gitignore b/.gitignore index f4b816d05..de4716a66 100644 --- a/.gitignore +++ b/.gitignore @@ -70,6 +70,7 @@ architecture.txt deps/jemalloc/jemalloc-3.6.0/ deps/jemalloc/jemalloc-4.1.0/ deps/jemalloc/jemalloc-4.2.1/ +deps/jemalloc/jemalloc-4.3.1/ #libdaemon deps/libdaemon/libdaemon-0.14/ diff --git a/include/thread.h b/include/thread.h index 874591767..a428e1f8c 100644 --- a/include/thread.h +++ b/include/thread.h @@ -24,6 +24,7 @@ #define __thread_h__ #include +#include "jemalloc.h" class Thread { @@ -31,7 +32,7 @@ class Thread Thread(); virtual ~Thread(); - int start(); + int start(bool jemalloc_tcache=true); int join(); int detach(); pthread_t self(); diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index 5fa6ba543..de2161078 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -262,6 +262,34 @@ MySQL_Monitor_State_Data::~MySQL_Monitor_State_Data() { } } +void * monitor_connect_pthread(void *arg) { + bool cache=false; + mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool)); + GloMyMon->monitor_connect(); + return NULL; +} + +void * monitor_ping_pthread(void *arg) { + bool cache=false; + mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool)); + GloMyMon->monitor_ping(); + return NULL; +} + +void * monitor_read_only_pthread(void *arg) { + bool cache=false; +// mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool)); + GloMyMon->monitor_read_only(); + return NULL; +} + +void * monitor_replication_lag_pthread(void *arg) { + bool cache=false; +// mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool)); + GloMyMon->monitor_replication_lag(); + return NULL; +} + MySQL_Monitor::MySQL_Monitor() { GloMyMon = this; @@ -1448,12 +1476,19 @@ __monitor_run: ConsumerThread **threads= (ConsumerThread **)malloc(sizeof(ConsumerThread *)*num_threads); for (unsigned int i=0;istart(); + threads[i]->start(false); } - std::thread * monitor_connect_thread = new std::thread(&MySQL_Monitor::monitor_connect,this); - std::thread * monitor_ping_thread = new std::thread(&MySQL_Monitor::monitor_ping,this); - std::thread * monitor_read_only_thread = new std::thread(&MySQL_Monitor::monitor_read_only,this); - std::thread * monitor_replication_lag_thread = new std::thread(&MySQL_Monitor::monitor_replication_lag,this); + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setstacksize (&attr, 64*1024); + pthread_t monitor_connect_thread; + pthread_create(&monitor_connect_thread, &attr, &monitor_connect_pthread,NULL); + pthread_t monitor_ping_thread; + pthread_create(&monitor_ping_thread, &attr, &monitor_ping_pthread,NULL); + pthread_t monitor_read_only_thread; + pthread_create(&monitor_read_only_thread, &attr, &monitor_read_only_pthread,NULL); + pthread_t monitor_replication_lag_thread; + pthread_create(&monitor_replication_lag_thread, &attr, &monitor_replication_lag_pthread,NULL); while (shutdown==false && mysql_thread___monitor_enabled==true) { unsigned int glover; if (GloMTH) { @@ -1492,10 +1527,10 @@ __monitor_run: threads[i]->join(); } free(threads); - monitor_connect_thread->join(); - monitor_ping_thread->join(); - monitor_read_only_thread->join(); - monitor_replication_lag_thread->join(); + pthread_join(monitor_connect_thread,NULL); + pthread_join(monitor_ping_thread,NULL); + pthread_join(monitor_read_only_thread,NULL); + pthread_join(monitor_replication_lag_thread,NULL); while (shutdown==false) { unsigned int glover; if (GloMTH) { diff --git a/lib/thread.cpp b/lib/thread.cpp index fb3403d77..32229a201 100644 --- a/lib/thread.cpp +++ b/lib/thread.cpp @@ -39,12 +39,19 @@ Thread::~Thread() } } -int Thread::start() +int Thread::start(bool jemalloc_tcache) { - int result = pthread_create(&m_tid, NULL, runThread, this); + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setstacksize (&attr, 64*1024); + int result = pthread_create(&m_tid, &attr, runThread, this); if (result == 0) { m_running = 1; } + if (jemalloc_tcache==false) { + bool cache=false; + mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool)); + } return result; } diff --git a/src/main.cpp b/src/main.cpp index 17409792e..b8a888a0f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -129,7 +129,8 @@ static volatile int load_; //__thread l_sfp *__thr_sfp=NULL; -const char *malloc_conf = "xmalloc:true,lg_tcache_max:16,purge:decay"; +//const char *malloc_conf = "xmalloc:true,lg_tcache_max:16,purge:decay"; +const char *malloc_conf = "xmalloc:true,lg_chunk:18,lg_tcache_max:12,purge:ratio"; //const char *malloc_conf = "prof_leak:true,lg_prof_sample:0,prof_final:true,xmalloc:true,lg_tcache_max:16"; int listen_fd;