diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index c65c17202..aa692ce1c 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -152,7 +152,8 @@ class MySQL_Thread int pipefd[2]; unsigned long long curtime; - + unsigned long long last_maintenance_time; + bool maintenance_loop; ProxySQL_Poll mypolls; pthread_t thread_id; int shutdown; diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 4148577fd..7cfa88a8d 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -1361,9 +1361,6 @@ void MySQL_Thread::run() { int rc; //int arg_on=1; - - unsigned long long oldtime=monotonic_time(); - curtime=monotonic_time(); spin_wrlock(&thread_mutex); @@ -1517,22 +1514,26 @@ void MySQL_Thread::run() { assert(__sync_bool_compare_and_swap(&mypolls.pending_listener_del,n,0)); } - curtime=monotonic_time(); + //curtime=monotonic_time(); spin_wrlock(&thread_mutex); mypolls.poll_timeout=0; // always reset this to 0 . If a session needs a specific timeout, it will set this one curtime=monotonic_time(); + if (curtime > last_maintenance_time + 200000) { // hardcoded value for now + last_maintenance_time=curtime; + maintenance_loop=true; + } else { + maintenance_loop=false; + } // update polls statistics mypolls.loops++; mypolls.loop_counters->incr(curtime/1000000); - if (curtime>(oldtime+(mysql_thread___poll_timeout*1000))) { - oldtime=curtime; + if (maintenance_loop) { GloQPro->update_query_processor_stats(); } - if (rc == -1 && errno == EINTR) // poll() timeout, try again continue; @@ -1678,16 +1679,18 @@ void MySQL_Thread::process_all_sessions() { } for (n=0; nlen; n++) { MySQL_Session *sess=(MySQL_Session *)mysql_sessions->index(n); - unsigned int numTrx=0; - unsigned long long sess_time = sess->IdleTime(); - if ( (sess_time/1000 > (unsigned long long)mysql_thread___max_transaction_time) || (sess_time/1000 > (unsigned long long)mysql_thread___wait_timeout) ) { - numTrx = sess->NumActiveTransactions(); - if (numTrx) { - // the session has idle transactions, kill it - if (sess_time/1000 > (unsigned long long)mysql_thread___max_transaction_time) sess->killed=true; - } else { - // the session is idle, kill it - if (sess_time/1000 > (unsigned long long)mysql_thread___wait_timeout) sess->killed=true; + if (maintenance_loop) { + unsigned int numTrx=0; + unsigned long long sess_time = sess->IdleTime(); + if ( (sess_time/1000 > (unsigned long long)mysql_thread___max_transaction_time) || (sess_time/1000 > (unsigned long long)mysql_thread___wait_timeout) ) { + numTrx = sess->NumActiveTransactions(); + if (numTrx) { + // the session has idle transactions, kill it + if (sess_time/1000 > (unsigned long long)mysql_thread___max_transaction_time) sess->killed=true; + } else { + // the session is idle, kill it + if (sess_time/1000 > (unsigned long long)mysql_thread___wait_timeout) sess->killed=true; + } } } if (sess->healthy==0) { @@ -1802,6 +1805,9 @@ MySQL_Thread::MySQL_Thread() { mysql_thread___server_version=NULL; mysql_thread___eventslog_filename=NULL; + last_maintenance_time=0; + maintenance_loop=true; + status_variables.queries=0; status_variables.queries_slow=0; status_variables.queries_backends_bytes_sent=0;