From f9177ac0296ef17137032ec3c8f30807ced630fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 14 Oct 2016 15:56:50 +0000 Subject: [PATCH] Added variable mysql-session_idle_ms --- include/MySQL_Thread.h | 3 ++- include/proxysql_structs.h | 2 ++ lib/MySQL_Thread.cpp | 21 +++++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index 51549a2ec..bcf8d723e 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -147,7 +147,7 @@ class MySQL_Thread struct epoll_event events[MY_EPOLL_THREAD_MAXEVENTS]; int efd; - int mysess_idx; + unsigned int mysess_idx; std::map sessmap; protected: @@ -295,6 +295,7 @@ class MySQL_Threads_Handler int connect_timeout_server; int connect_timeout_server_max; int free_connections_pct; + int session_idle_ms; bool sessions_sort; char *default_schema; char *interfaces; diff --git a/include/proxysql_structs.h b/include/proxysql_structs.h index e407f1637..50e513784 100644 --- a/include/proxysql_structs.h +++ b/include/proxysql_structs.h @@ -819,6 +819,7 @@ __thread bool mysql_thread___commands_stats; __thread bool mysql_thread___query_digests; __thread bool mysql_thread___default_reconnect; __thread bool mysql_thread___sessions_sort; +__thread bool mysql_thread___session_idle_ms; /* variables used for Query Cache */ __thread int mysql_thread___query_cache_size_MB; @@ -905,6 +906,7 @@ extern __thread bool mysql_thread___commands_stats; extern __thread bool mysql_thread___query_digests; extern __thread bool mysql_thread___default_reconnect; extern __thread bool mysql_thread___sessions_sort; +extern __thread bool mysql_thread___session_idle_ms; /* variables used for Query Cache */ extern __thread int mysql_thread___query_cache_size_MB; diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 767bce287..c27a6a86d 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -208,6 +208,7 @@ static char * mysql_thread_variables_names[]= { (char *)"eventslog_filesize", (char *)"default_charset", (char *)"free_connections_pct", + (char *)"session_idle_ms", (char *)"have_compress", (char *)"client_found_rows", (char *)"interfaces", @@ -297,6 +298,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() { variables.connect_timeout_server=1000; variables.connect_timeout_server_max=10000; variables.free_connections_pct=10; + variables.session_idle_ms=1000; variables.connect_retries_delay=1; variables.monitor_enabled=true; variables.monitor_history=600000; @@ -559,6 +561,7 @@ int MySQL_Threads_Handler::get_variable_int(char *name) { if (!strcasecmp(name,"long_query_time")) return (int)variables.long_query_time; if (!strcasecmp(name,"query_cache_size_MB")) return (int)variables.query_cache_size_MB; if (!strcasecmp(name,"free_connections_pct")) return (int)variables.free_connections_pct; + if (!strcasecmp(name,"session_idle_ms")) return (int)variables.session_idle_ms; if (!strcasecmp(name,"ping_interval_server_msec")) return (int)variables.ping_interval_server_msec; if (!strcasecmp(name,"ping_timeout_server")) return (int)variables.ping_timeout_server; if (!strcasecmp(name,"have_compress")) return (int)variables.have_compress; @@ -731,6 +734,10 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f sprintf(intbuf,"%d",variables.free_connections_pct); return strdup(intbuf); } + if (!strcasecmp(name,"session_idle_ms")) { + sprintf(intbuf,"%d",variables.session_idle_ms); + return strdup(intbuf); + } if (!strcasecmp(name,"connect_retries_delay")) { sprintf(intbuf,"%d",variables.connect_retries_delay); return strdup(intbuf); @@ -1085,6 +1092,15 @@ bool MySQL_Threads_Handler::set_variable(char *name, char *value) { // this is t return false; } } + if (!strcasecmp(name,"session_idle_ms")) { + int intv=atoi(value); + if (intv >= 100 && intv <= 3600*1000) { + variables.session_idle_ms=intv; + return true; + } else { + return false; + } + } if (!strcasecmp(name,"max_connections")) { int intv=atoi(value); if (intv >= 1 && intv <= 1000*1000) { @@ -2238,7 +2254,7 @@ __run_skip_1a: if (mysess_idx + SESS_TO_SCAN > mysql_sessions->len) { mysess_idx=0; } - int i; + unsigned int i; for (i=0;ilen; i++) { uint32_t sess_pos=mysess_idx; MySQL_Session *mysess=(MySQL_Session *)mysql_sessions->index(sess_pos); @@ -2246,7 +2262,7 @@ __run_skip_1a: unsigned long long sess_time = mysess->IdleTime(); if ( (sess_time/1000 > (unsigned long long)mysql_thread___wait_timeout) ) { mysess->killed=true; - uint32_t sess_thr_id=mysess->thread_session_id; + //uint32_t sess_thr_id=mysess->thread_session_id; MySQL_Data_Stream *tmp_myds=mysess->client_myds; int dsidx=tmp_myds->poll_fds_idx; //fprintf(stderr,"Removing session %p, DS %p idx %d\n",mysess,tmp_myds,dsidx); @@ -2592,6 +2608,7 @@ void MySQL_Thread::refresh_variables() { mysql_thread___connect_timeout_server=GloMTH->get_variable_int((char *)"connect_timeout_server"); mysql_thread___connect_timeout_server_max=GloMTH->get_variable_int((char *)"connect_timeout_server_max"); mysql_thread___free_connections_pct=GloMTH->get_variable_int((char *)"free_connections_pct"); + mysql_thread___session_idle_ms=GloMTH->get_variable_int((char *)"session_idle_ms"); mysql_thread___connect_retries_delay=GloMTH->get_variable_int((char *)"connect_retries_delay"); if (mysql_thread___monitor_username) free(mysql_thread___monitor_username);