From 74c4bf321083378393bcd2bae5d372be79533a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sat, 10 Sep 2016 13:38:44 +0000 Subject: [PATCH] Added STRESSTEST_POOL Enabling STRESSTEST_POOL ProxySQL will do a lot of loops in the connection pool This is for internal testing ONLY!!!! DO NOT ENABLE IT --- include/MySQL_HostGroups_Manager.h | 7 +++++++ lib/MySQL_Session.cpp | 23 ++++++++++++++++------- lib/mysql_data_stream.cpp | 5 ++++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/MySQL_HostGroups_Manager.h b/include/MySQL_HostGroups_Manager.h index 723c2bb23..44ac6d3b9 100644 --- a/include/MySQL_HostGroups_Manager.h +++ b/include/MySQL_HostGroups_Manager.h @@ -3,6 +3,13 @@ #include "proxysql.h" #include "cpp.h" + +/* + Enabling STRESSTEST_POOL ProxySQL will do a lot of loops in the connection pool + This is for internal testing ONLY!!!! +#define STRESSTEST_POOL +*/ + #define MYHGM_MYSQL_SERVERS "CREATE TABLE mysql_servers ( hostgroup_id INT NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , weight INT CHECK (weight >= 0) NOT NULL DEFAULT 1 , status INT CHECK (status IN (0, 1, 2, 3, 4)) NOT NULL DEFAULT 0 , compression INT CHECK (compression >=0 AND compression <= 102400) NOT NULL DEFAULT 0 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 1000 , max_replication_lag INT CHECK (max_replication_lag >= 0 AND max_replication_lag <= 126144000) NOT NULL DEFAULT 0 , use_ssl INT CHECK (use_ssl IN(0,1)) NOT NULL DEFAULT 0 , max_latency_ms INT UNSIGNED CHECK (max_latency_ms>=0) NOT NULL DEFAULT 0 , comment VARCHAR NOT NULL DEFAULT '' , mem_pointer INT NOT NULL DEFAULT 0 , PRIMARY KEY (hostgroup_id, hostname, port) )" #define MYHGM_MYSQL_SERVERS_INCOMING "CREATE TABLE mysql_servers_incoming ( hostgroup_id INT NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , weight INT CHECK (weight >= 0) NOT NULL DEFAULT 1 , status INT CHECK (status IN (0, 1, 2, 3, 4)) NOT NULL DEFAULT 0 , compression INT CHECK (compression >=0 AND compression <= 102400) NOT NULL DEFAULT 0 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 1000 , max_replication_lag INT CHECK (max_replication_lag >= 0 AND max_replication_lag <= 126144000) NOT NULL DEFAULT 0 , use_ssl INT CHECK (use_ssl IN(0,1)) NOT NULL DEFAULT 0 , max_latency_ms INT UNSIGNED CHECK (max_latency_ms>=0) NOT NULL DEFAULT 0 , comment VARCHAR NOT NULL DEFAULT '' , PRIMARY KEY (hostgroup_id, hostname, port))" #define MYHGM_MYSQL_REPLICATION_HOSTGROUPS "CREATE TABLE mysql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>0) , comment VARCHAR , UNIQUE (reader_hostgroup))" diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index b090ecb04..0327d7906 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -2124,21 +2124,30 @@ void MySQL_Session::handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED // if (rand()%3==0) { MySQL_Connection *mc=NULL; - //mc=thread->get_MyConn_local(mybe->hostgroup_id); // experimental , #644 +#ifdef STRESSTEST_POOL int i=100; while (i) { + if (mc==NULL) { + mc=MyHGM->get_MyConn_from_pool(mybe->hostgroup_id); + } + if (mc) { + mybe->server_myds->attach_connection(mc); + if (i > 1) { + mybe->server_myds->return_MySQL_Connection_To_Pool(); + mc=NULL; + } + } + i--; + } +#else + mc=thread->get_MyConn_local(mybe->hostgroup_id); // experimental , #644 if (mc==NULL) { mc=MyHGM->get_MyConn_from_pool(mybe->hostgroup_id); } if (mc) { mybe->server_myds->attach_connection(mc); - if (i > 1) { - mybe->server_myds->return_MySQL_Connection_To_Pool(); - mc=NULL; - } - } - i--; } +#endif // } proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 5, "Sess=%p -- server_myds=%p -- MySQL_Connection %p\n", this, mybe->server_myds, mybe->server_myds->myconn); if (mybe->server_myds->myconn==NULL) { diff --git a/lib/mysql_data_stream.cpp b/lib/mysql_data_stream.cpp index 44f2dd9b9..3879ba9fb 100644 --- a/lib/mysql_data_stream.cpp +++ b/lib/mysql_data_stream.cpp @@ -969,8 +969,11 @@ void MySQL_Data_Stream::return_MySQL_Connection_To_Pool() { detach_connection(); unplug_backend(); //mc->async_state_machine=ASYNC_IDLE; - //sess->thread->push_MyConn_local(mc); +#ifdef STRESSTEST_POOL MyHGM->push_MyConn_to_pool(mc); // #644 +#else + sess->thread->push_MyConn_local(mc); +#endif } }