Optimization on connections reset

Limit the size of the queue #1185
Reuse the same user #1186
pull/1209/head
René Cannaò 9 years ago
parent 225e1f15fc
commit ec4049ac1e

@ -392,6 +392,7 @@ class MySQL_Threads_Handler
uint16_t server_capabilities;
int poll_timeout;
int poll_timeout_on_failure;
int connpoll_reset_queue_length;
char *eventslog_filename;
int eventslog_filesize;
// SSL related, proxy to server

@ -76,7 +76,17 @@ static void * HGCU_thread_run() {
myconn->reset();
myconn=(MySQL_Connection *)conn_array->index(i);
if (myconn->mysql->net.vio && myconn->mysql->net.fd && myconn->mysql->net.buff) {
statuses[i]=mysql_change_user_start(&ret[i], myconn->mysql, myconn->userinfo->username, myconn->userinfo->password, myconn->userinfo->schemaname);
MySQL_Connection_userinfo *userinfo = myconn->userinfo;
char *auth_password = NULL;
if (userinfo->password) {
if (userinfo->password[0]=='*') { // we don't have the real password, let's pass sha1
auth_password=userinfo->sha1_pass;
} else {
auth_password=userinfo->password;
}
}
//async_exit_status = mysql_change_user_start(&ret_bool,mysql,_ui->username, auth_password, _ui->schemaname);
statuses[i]=mysql_change_user_start(&ret[i], myconn->mysql, myconn->userinfo->username, auth_password, myconn->userinfo->schemaname);
if (myconn->mysql->net.vio==NULL || myconn->mysql->net.fd==0 || myconn->mysql->net.buff==NULL) {
statuses[i]=0; ret[i]=1;
}
@ -1405,11 +1415,11 @@ MySQL_Connection * MySQL_HostGroups_Manager::get_MyConn_from_pool(unsigned int _
void MySQL_HostGroups_Manager::destroy_MyConn_from_pool(MySQL_Connection *c) {
bool to_del=true; // the default, legacy behavior
MySrvC *mysrvc=(MySrvC *)c->parent;
if (mysrvc->status==MYSQL_SERVER_STATUS_ONLINE && c->send_quit && queue.size() < 100) {
if (mysrvc->status==MYSQL_SERVER_STATUS_ONLINE && c->send_quit && queue.size() < __sync_fetch_and_add(&GloMTH->variables.connpoll_reset_queue_length,0)) {
// overall, the backend seems healthy and so it is the connection. Try to reset it
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Trying to reset MySQL_Connection %p, server %s:%d\n", c, mysrvc->address, mysrvc->port);
to_del=false;
c->userinfo->set(mysql_thread___monitor_username,mysql_thread___monitor_password,mysql_thread___default_schema,NULL);
//c->userinfo->set(mysql_thread___monitor_username,mysql_thread___monitor_password,mysql_thread___default_schema,NULL);
queue.add(c);
} else {
// we lock only this part of the code because we need to remove the connection from ConnectionsUsed

@ -283,6 +283,7 @@ static char * mysql_thread_variables_names[]= {
(char *)"init_connect",
(char *)"default_sql_mode",
(char *)"default_time_zone",
(char *)"connpoll_reset_queue_length",
(char *)"stats_time_backend_query",
(char *)"stats_time_query_processor",
NULL
@ -383,6 +384,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() {
variables.autocommit_false_not_reusable=false;
variables.query_digests=true;
variables.query_digests_lowercase=false;
variables.connpoll_reset_queue_length = 50;
variables.stats_time_backend_query=true;
variables.stats_time_query_processor=true;
variables.sessions_sort=true;
@ -628,6 +630,7 @@ int MySQL_Threads_Handler::get_variable_int(char *name) {
if (!strcasecmp(name,"commands_stats")) return (int)variables.commands_stats;
if (!strcasecmp(name,"query_digests")) return (int)variables.query_digests;
if (!strcasecmp(name,"query_digests_lowercase")) return (int)variables.query_digests_lowercase;
if (!strcasecmp(name,"connpoll_reset_queue_length")) return (int)variables.connpoll_reset_queue_length;
if (!strcasecmp(name,"stats_time_backend_query")) return (int)variables.stats_time_backend_query;
if (!strcasecmp(name,"stats_time_query_processor")) return (int)variables.stats_time_query_processor;
if (!strcasecmp(name,"sessions_sort")) return (int)variables.sessions_sort;
@ -791,6 +794,10 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f
sprintf(intbuf,"%d",variables.shun_on_failures);
return strdup(intbuf);
}
if (!strcasecmp(name,"connpoll_reset_queue_length")) {
sprintf(intbuf,"%d",variables.connpoll_reset_queue_length);
return strdup(intbuf);
}
if (!strcasecmp(name,"shun_recovery_time_sec")) {
sprintf(intbuf,"%d",variables.shun_recovery_time_sec);
return strdup(intbuf);
@ -1649,6 +1656,15 @@ bool MySQL_Threads_Handler::set_variable(char *name, char *value) { // this is t
return false;
}
}
if (!strcasecmp(name,"connpoll_reset_queue_length")) {
int intv=atoi(value);
if (intv >= 0 && intv <= 1000) {
variables.connpoll_reset_queue_length=intv;
return true;
} else {
return false;
}
}
if (!strcasecmp(name,"default_charset")) {
if (vallen) {
CHARSET_INFO * c=proxysql_find_charset_name(value);

Loading…
Cancel
Save