diff --git a/.gitignore b/.gitignore index 413bab59e..2253f1a90 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ binaries/*deb binaries/*rpm tools/eventslog_reader_sample src/proxysql-save.cfg +src/*log* proxysql-2.0.0/ docker/images/proxysql/rhel-compliant/rpmmacros diff --git a/include/Base_Session.h b/include/Base_Session.h index ccf8aba5f..5dc818ed9 100644 --- a/include/Base_Session.h +++ b/include/Base_Session.h @@ -120,6 +120,9 @@ class Base_Session { */ void housekeeping_before_pkts(); virtual void create_new_session_and_reset_connection(DS *_myds) = 0; + + + }; #endif // CLASS_BASE_SESSION_H diff --git a/include/Base_Thread.h b/include/Base_Thread.h index 3ae475a76..5992caecb 100644 --- a/include/Base_Thread.h +++ b/include/Base_Thread.h @@ -77,6 +77,15 @@ class Base_Thread { template void ProcessAllMyDS_BeforePoll(); template void run_SetAllSession_ToProcess0(); + +#if ENABLE_TIMER + // for now this is not accessible via Admin/Prometheus , thus useful only with gdb + struct { + TimerCount Sessions_Handlers; + TimerCount Connections_Handlers; + } Timers; +#endif // ENABLE_TIMER + friend class MySQL_Thread; friend class PgSQL_Thread; }; diff --git a/include/proxysql_debug.h b/include/proxysql_debug.h index bf9fa013c..c6416497e 100644 --- a/include/proxysql_debug.h +++ b/include/proxysql_debug.h @@ -12,6 +12,38 @@ extern int gdbg; #ifndef __PROXYSQL_DEBUG_H #define __PROXYSQL_DEBUG_H +#include +#include +#include + +#include "proxysql_macros.h" + +#if ENABLE_TIMER // this is defined in proxysql_macros.h +class TimerCount { + public: + std::chrono::duration Timer = std::chrono::seconds(0); + unsigned int Count = 0; +}; + +class Timer { + public: + Timer(TimerCount& tc) : totalTime(tc.Timer) { + start = std::chrono::high_resolution_clock::now(); + tc.Count++; + } + + ~Timer() { + auto end = std::chrono::high_resolution_clock::now(); + std::chrono::duration elapsed = end - start; + totalTime += elapsed; + } + private: + //std::atomic>& totalTime; // If using atomic , use this instead + std::chrono::duration& totalTime; + std::chrono::time_point start; +}; +#endif // ENABLE_TIMER + #ifdef DEBUG #define PROXY_TRACE() { proxy_debug(PROXY_DEBUG_GENERIC,10,"TRACE\n"); } //#define PROXY_TRACE2() { proxy_info("TRACE\n"); } diff --git a/include/proxysql_macros.h b/include/proxysql_macros.h index d7090b1c6..f83cca736 100644 --- a/include/proxysql_macros.h +++ b/include/proxysql_macros.h @@ -1,4 +1,5 @@ - +#ifndef PROXYSQL_MACROS_H +#define PROXYSQL_MACROS_H #define strdup_null(__c) ( __c ? strdup(__c) : __c ) #define char_malloc (char *)malloc #define free_null(__c) { if(__c) { free(__c); __c=NULL; } } @@ -65,3 +66,8 @@ # define unlikely(x) !!(x) #endif #endif /* PROXYSQL_LIKELY */ + +#ifndef ENABLE_TIMER +#define ENABLE_TIMER false +#endif // ENABLE_TIMER +#endif // PROXYSQL_MACROS_H diff --git a/lib/PgSQL_Connection.cpp b/lib/PgSQL_Connection.cpp index 311d7a3ff..f83b6595c 100644 --- a/lib/PgSQL_Connection.cpp +++ b/lib/PgSQL_Connection.cpp @@ -415,6 +415,7 @@ PgSQL_Connection_Placeholder::PgSQL_Connection_Placeholder() { } options.client_flag = 0; + options.server_capabilities = 0; options.compression_min_length=0; options.server_version=NULL; options.last_set_autocommit=-1; // -1 = never set @@ -3025,6 +3026,9 @@ void PgSQL_Connection::next_event(PG_ASYNC_ST new_st) { PG_ASYNC_ST PgSQL_Connection::handler(short event) { +#if ENABLE_TIMER + Timer timer(myds->sess->thread->Timers.Connections_Handlers); +#endif // ENABLE_TIMER unsigned long long processed_bytes = 0; // issue #527 : this variable will store the amount of bytes processed during this event if (pgsql_conn == NULL) { // it is the first time handler() is being called diff --git a/lib/PgSQL_Session.cpp b/lib/PgSQL_Session.cpp index b2560f686..ff39f1e57 100644 --- a/lib/PgSQL_Session.cpp +++ b/lib/PgSQL_Session.cpp @@ -4389,6 +4389,9 @@ void PgSQL_Session::handler_rc0_Process_GTID(PgSQL_Connection* myconn) { } int PgSQL_Session::handler() { +#if ENABLE_TIMER + Timer timer(thread->Timers.Sessions_Handlers); +#endif // ENABLE_TIMER int handler_ret = 0; bool prepared_stmt_with_no_params = false; bool wrong_pass = false; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 61de0b506..d1088fc12 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -2512,9 +2512,9 @@ ProxySQL_Admin::ProxySQL_Admin() : variables.web_port_old = variables.web_port; variables.web_verbosity = 0; variables.p_memory_metrics_interval = 61; + all_modules_started = false; #ifdef DEBUG variables.debug=GloVars.global.gdbg; - all_modules_started = false; debug_output = 1; proxysql_set_admin_debug_output(debug_output); #endif /* DEBUG */ diff --git a/src/main.cpp b/src/main.cpp index 377227d06..f38ebee6f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,6 +48,7 @@ using json = nlohmann::json; #include #include +#include /* extern "C" MySQL_LDAP_Authentication * create_MySQL_LDAP_Authentication_func() { @@ -61,6 +62,14 @@ using std::string; using std::vector; +void sleep_iter(unsigned int iter) { + usleep(50*iter); +#ifdef RUNNING_ON_VALGRIND + usleep((1000+rand()%1000)*iter); +#endif // RUNNING_ON_VALGRIND +} + + volatile create_MySQL_LDAP_Authentication_t * create_MySQL_LDAP_Authentication = NULL; void * __mysql_ldap_auth; @@ -408,7 +417,7 @@ using namespace std; //__cmd_proxysql_config_file=NULL; #define MAX_EVENTS 100 -static volatile int load_; +std::atomic load_; //__thread l_sfp *__thr_sfp=NULL; //#ifdef DEBUG @@ -474,8 +483,9 @@ void * mysql_worker_thread_func(void *arg) { worker->init(); // worker->poll_listener_add(listen_fd); // worker->poll_listener_add(socket_fd); - __sync_fetch_and_sub(&load_,1); - do { usleep(50); } while (load_); + load_ -= 1; + unsigned int iter = 0; + do { sleep_iter(++iter); } while (load_); worker->run(); //delete worker; @@ -505,8 +515,9 @@ void * mysql_worker_thread_func_idles(void *arg) { worker->init(); // worker->poll_listener_add(listen_fd); // worker->poll_listener_add(socket_fd); - __sync_fetch_and_sub(&load_,1); - do { usleep(50); } while (load_); + load_ -= 1; + unsigned int iter = 0; + do { sleep_iter(++iter); } while (load_); worker->run(); //delete worker; @@ -537,8 +548,9 @@ void* pgsql_worker_thread_func(void* arg) { worker->init(); // worker->poll_listener_add(listen_fd); // worker->poll_listener_add(socket_fd); - __sync_fetch_and_sub(&load_, 1); - do { usleep(50); } while (load_); + load_ -= 1; + unsigned int iter = 0; + do { sleep_iter(++iter); } while (load_); worker->run(); //delete worker; @@ -568,8 +580,9 @@ void* pgsql_worker_thread_func_idles(void* arg) { worker->init(); // worker->poll_listener_add(listen_fd); // worker->poll_listener_add(socket_fd); - __sync_fetch_and_sub(&load_, 1); - do { usleep(50); } while (load_); + load_ -= 1; + unsigned int iter = 0; + do { sleep_iter(++iter); } while (load_); worker->run(); //delete worker; @@ -1331,11 +1344,8 @@ void ProxySQL_Main_init_phase3___start_all() { #endif } - do { /* nothing */ -#ifdef DEBUG - usleep(5+rand()%10); -#endif - } while (load_ != 1); + unsigned int iter = 0; + do { sleep_iter(++iter); } while (load_ != 1); load_ = 0; __sync_fetch_and_add(&GloMTH->status_variables.threads_initialized, 1);