From 2fc393f74384e223bc88a8fb9c94e02e137e4184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 5 Aug 2015 07:44:59 +0000 Subject: [PATCH] Improvement on processlist: - table is populated only if command includes "stats_mysql_processlist" - new command state "Delay" --- lib/MySQL_Thread.cpp | 8 +++++++- lib/ProxySQL_Admin.cpp | 14 +++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 7c48b9940..4df713d36 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -1178,6 +1178,8 @@ void MySQL_Thread::run() { rc=poll(mypolls.fds,mypolls.len, ( mypolls.poll_timeout ? ( mypolls.poll_timeout/1000 < (unsigned int) mysql_thread___poll_timeout ? mypolls.poll_timeout/1000 : mysql_thread___poll_timeout ) : mysql_thread___poll_timeout ) ); proxy_debug(PROXY_DEBUG_NET,5,"%s\n", "Returning poll"); + 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 @@ -1646,7 +1648,11 @@ SQLite3_result * MySQL_Threads_Handler::SQL3_Processlist() { pta[7]=strdup("Connect"); break; case PROCESSING_QUERY: - pta[7]=strdup("Query"); + if (sess->pause_until > sess->thread->curtime) { + pta[7]=strdup("Delay"); + } else { + pta[7]=strdup("Query"); + } break; case WAITING_CLIENT_DATA: pta[7]=strdup("Sleep"); diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 5f547c766..28bc37b99 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -820,11 +820,6 @@ void admin_session_handler(MySQL_Session *sess, ProxySQL_Admin *pa, PtrSize_t *p //fprintf(stderr,"%s----\n",query_no_space); - pthread_mutex_lock(&admin_mutex); - ProxySQL_Admin *SPA=(ProxySQL_Admin *)pa; - SPA->stats___mysql_processlist(); - pthread_mutex_unlock(&admin_mutex); - if (sess->stats==false) { if ((query_no_space_length>8) && (!strncasecmp("PROXYSQL ", query_no_space, 8))) { proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received PROXYSQL command\n"); @@ -836,6 +831,15 @@ void admin_session_handler(MySQL_Session *sess, ProxySQL_Admin *pa, PtrSize_t *p run_query=admin_handler_command_load_or_save(query_no_space, query_no_space_length, sess, pa, &query, &query_length); goto __run_query; } + + + if (strstr(query_no_space,"stats_mysql_processlist")) { + pthread_mutex_lock(&admin_mutex); + ProxySQL_Admin *SPA=(ProxySQL_Admin *)pa; + SPA->stats___mysql_processlist(); + pthread_mutex_unlock(&admin_mutex); + goto __run_query; + } } // FIXME: this should be removed, it is just a POC for issue #253 . What is important is the call to GloMTH->signal_all_threads();