From 330feaae8b74121fe0a6222f3f875cf1f55f7ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 5 Jan 2022 12:18:24 +0100 Subject: [PATCH 1/3] Changed variables order in PtrSizeArray/PtrArray This minor change seems to improve cache affinity, because "len" is the variable that is read mostly --- include/gen_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/gen_utils.h b/include/gen_utils.h index 7cda6981d..f2fa0105b 100644 --- a/include/gen_utils.h +++ b/include/gen_utils.h @@ -41,9 +41,9 @@ class PtrArray { size=new_size; } public: - void **pdata; unsigned int len; unsigned int size; + void **pdata; PtrArray(unsigned int __size=0) { len=0; pdata=NULL; @@ -128,9 +128,9 @@ class PtrSizeArray { public: void * operator new(size_t); void operator delete(void *); - PtrSize_t *pdata; unsigned int len; unsigned int size; + PtrSize_t *pdata; PtrSizeArray(unsigned int __size=0); ~PtrSizeArray(); From 630124b774af816d4f6b48d7ee6762e53d7ca408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Thu, 6 Jan 2022 22:54:49 +0100 Subject: [PATCH 2/3] Minor improvement for cache affinity --- include/MySQL_Thread.h | 1 + include/proxysql_structs.h | 2 +- lib/MySQL_Thread.cpp | 13 ++++++++++++- lib/mysql_data_stream.cpp | 5 +++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index 4c09da3a2..710955e7b 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -178,6 +178,7 @@ class MySQL_Thread unsigned long long curtime; unsigned long long pre_poll_time; unsigned long long last_maintenance_time; + unsigned long long last_move_to_idle_thread_time; std::atomic atomic_curtime; PtrArray *mysql_sessions; PtrArray *mirror_queue_mysql_sessions; diff --git a/include/proxysql_structs.h b/include/proxysql_structs.h index 90f0735de..50ccfcfea 100644 --- a/include/proxysql_structs.h +++ b/include/proxysql_structs.h @@ -493,8 +493,8 @@ struct __SQP_query_parser_t { }; struct _PtrSize_t { - void *ptr; unsigned int size; + void *ptr; }; // struct for debugging module #ifdef DEBUG diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index a416d06ab..11a93fa1f 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -2961,13 +2961,23 @@ void MySQL_Thread::run___get_multiple_idle_connections(int& num_idles) { // this function was inline in MySQL_Thread::run() void MySQL_Thread::ProcessAllMyDS_BeforePoll() { + bool check_if_move_to_idle_thread = false; +#ifdef IDLE_THREADS + if (GloVars.global.idle_threads) { + if (curtime > last_move_to_idle_thread_time + (unsigned long long)mysql_thread___session_idle_ms * 1000) { + last_move_to_idle_thread_time=curtime; + check_if_move_to_idle_thread=true; + } + } +#endif for (unsigned int n = 0; n < mypolls.len; n++) { MySQL_Data_Stream *myds=NULL; myds=mypolls.myds[n]; mypolls.fds[n].revents=0; if (myds) { #ifdef IDLE_THREADS - if (GloVars.global.idle_threads) { + //if (GloVars.global.idle_threads) { + if (check_if_move_to_idle_thread == true) { // here we try to move it to the maintenance thread if (myds->myds_type==MYDS_FRONTEND && myds->sess) { if (myds->DSS==STATE_SLEEP && myds->sess->status==WAITING_CLIENT_DATA) { @@ -4051,6 +4061,7 @@ MySQL_Thread::MySQL_Thread() { mysql_thread___ssl_p2s_crlpath=NULL; last_maintenance_time=0; + last_move_to_idle_thread_time=0; maintenance_loop=true; retrieve_gtids_required = false; diff --git a/lib/mysql_data_stream.cpp b/lib/mysql_data_stream.cpp index 1324e8d96..5f27ddff9 100644 --- a/lib/mysql_data_stream.cpp +++ b/lib/mysql_data_stream.cpp @@ -896,8 +896,9 @@ int MySQL_Data_Stream::read_pkts() { int MySQL_Data_Stream::buffer2array() { int ret=0; bool fast_mode=sess->session_fast_forward; - if (queue_data(queueIN)==0) return ret; - if ((queueIN.pkt.size==0) && queue_data(queueIN) Date: Fri, 7 Jan 2022 00:56:52 +0100 Subject: [PATCH 3/3] Removing a comment --- lib/MySQL_Thread.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 11a93fa1f..94bba7c7a 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -2965,7 +2965,7 @@ void MySQL_Thread::ProcessAllMyDS_BeforePoll() { #ifdef IDLE_THREADS if (GloVars.global.idle_threads) { if (curtime > last_move_to_idle_thread_time + (unsigned long long)mysql_thread___session_idle_ms * 1000) { - last_move_to_idle_thread_time=curtime; + last_move_to_idle_thread_time=curtime; check_if_move_to_idle_thread=true; } } @@ -2976,7 +2976,6 @@ void MySQL_Thread::ProcessAllMyDS_BeforePoll() { mypolls.fds[n].revents=0; if (myds) { #ifdef IDLE_THREADS - //if (GloVars.global.idle_threads) { if (check_if_move_to_idle_thread == true) { // here we try to move it to the maintenance thread if (myds->myds_type==MYDS_FRONTEND && myds->sess) {