MDEV-6150 Speed up connection speed by moving creation of THD to new thread

Creating a CONNECT object on client connect and pass this to the working thread which creates the THD.
Split LOCK_thread_count to different mutexes
Added LOCK_thread_start to syncronize threads
Moved most usage of LOCK_thread_count to dedicated functions
Use next_thread_id() instead of thread_id++

Other things:
- Thread id now starts from 1 instead of 2
- Added cast for thread_id as thread id is now of type my_thread_id
- Made THD->host const (To ensure it's not changed)
- Removed some DBUG_PRINT() about entering/exiting mutex as these was already logged by mutex code
- Fixed that aborted_connects and connection_errors_internal are counted in all cases
- Don't take locks for current_linfo when we set it (not needed as it was 0 before)
This commit is contained in:
Monty 2016-02-01 12:45:39 +02:00
commit 3d4a7390c1
50 changed files with 872 additions and 545 deletions

View file

@ -37,8 +37,6 @@
#include "spd_ping_table.h"
#include "spd_malloc.h"
extern ulong *spd_db_att_thread_id;
extern handlerton *spider_hton_ptr;
extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
pthread_mutex_t spider_conn_id_mutex;
@ -2269,9 +2267,7 @@ void *spider_bg_conn_action(
my_thread_end();
DBUG_RETURN(NULL);
}
pthread_mutex_lock(&LOCK_thread_count);
thd->thread_id = (*spd_db_att_thread_id)++;
pthread_mutex_unlock(&LOCK_thread_count);
thd->thread_id = next_thread_id();
#ifdef HAVE_PSI_INTERFACE
mysql_thread_set_psi_id(thd->thread_id);
#endif
@ -2782,9 +2778,7 @@ void *spider_bg_sts_action(
#endif
DBUG_RETURN(NULL);
}
pthread_mutex_lock(&LOCK_thread_count);
thd->thread_id = (*spd_db_att_thread_id)++;
pthread_mutex_unlock(&LOCK_thread_count);
thd->thread_id = next_thread_id();
#ifdef HAVE_PSI_INTERFACE
mysql_thread_set_psi_id(thd->thread_id);
#endif
@ -3164,9 +3158,7 @@ void *spider_bg_crd_action(
#endif
DBUG_RETURN(NULL);
}
pthread_mutex_lock(&LOCK_thread_count);
thd->thread_id = (*spd_db_att_thread_id)++;
pthread_mutex_unlock(&LOCK_thread_count);
thd->thread_id = next_thread_id();
#ifdef HAVE_PSI_INTERFACE
mysql_thread_set_psi_id(thd->thread_id);
#endif
@ -3653,9 +3645,7 @@ void *spider_bg_mon_action(
my_thread_end();
DBUG_RETURN(NULL);
}
pthread_mutex_lock(&LOCK_thread_count);
thd->thread_id = (*spd_db_att_thread_id)++;
pthread_mutex_unlock(&LOCK_thread_count);
thd->thread_id = next_thread_id();
#ifdef HAVE_PSI_INTERFACE
mysql_thread_set_psi_id(thd->thread_id);
#endif

View file

@ -737,7 +737,8 @@ int spider_db_errorno(
"to %ld: %d %s\n",
l_time->tm_year + 1900, l_time->tm_mon + 1, l_time->tm_mday,
l_time->tm_hour, l_time->tm_min, l_time->tm_sec,
current_thd->thread_id, error_num, conn->db_conn->get_error());
(ulong) current_thd->thread_id, error_num,
conn->db_conn->get_error());
}
if (!conn->mta_conn_mutex_unlock_later)
{
@ -757,7 +758,8 @@ int spider_db_errorno(
"to %ld: %d %s\n",
l_time->tm_year + 1900, l_time->tm_mon + 1, l_time->tm_mday,
l_time->tm_hour, l_time->tm_min, l_time->tm_sec,
current_thd->thread_id, error_num, conn->db_conn->get_error());
(ulong) current_thd->thread_id, error_num,
conn->db_conn->get_error());
}
if (!conn->mta_conn_mutex_unlock_later)
{

View file

@ -1717,7 +1717,7 @@ int spider_db_mysql::exec_query(
l_time->tm_hour, l_time->tm_min, l_time->tm_sec,
security_ctx->user ? security_ctx->user : "system user",
security_ctx->host_or_ip,
thd->thread_id,
(ulong) thd->thread_id,
tmp_query_str.c_ptr_safe());
}
if (log_result_error_with_sql & 1)
@ -1731,7 +1731,7 @@ int spider_db_mysql::exec_query(
"sql: %s\n",
l_time->tm_year + 1900, l_time->tm_mon + 1, l_time->tm_mday,
l_time->tm_hour, l_time->tm_min, l_time->tm_sec,
thd->thread_id, conn->tgt_host, db_conn->thread_id,
(ulong) thd->thread_id, conn->tgt_host, (ulong) db_conn->thread_id,
tmp_query_str.c_ptr_safe());
}
}
@ -1745,7 +1745,7 @@ int spider_db_mysql::exec_query(
"affected_rows: %llu id: %llu status: %u warning_count: %u\n",
l_time->tm_year + 1900, l_time->tm_mon + 1, l_time->tm_mday,
l_time->tm_hour, l_time->tm_min, l_time->tm_sec,
conn->tgt_host, db_conn->thread_id, thd->thread_id,
conn->tgt_host, (ulong) db_conn->thread_id, (ulong) thd->thread_id,
db_conn->affected_rows, db_conn->insert_id,
db_conn->server_status, db_conn->warning_count);
if (spider_param_log_result_errors() >= 3)
@ -1760,7 +1760,7 @@ int spider_db_mysql::exec_query(
"affected_rows: %llu id: %llu status: %u warning_count: %u\n",
l_time->tm_year + 1900, l_time->tm_mon + 1, l_time->tm_mday,
l_time->tm_hour, l_time->tm_min, l_time->tm_sec,
conn->tgt_host, db_conn->thread_id, thd->thread_id,
conn->tgt_host, (ulong) db_conn->thread_id, (ulong) thd->thread_id,
db_conn->affected_rows, db_conn->insert_id,
db_conn->server_status, db_conn->warning_count);
}
@ -1889,8 +1889,8 @@ void spider_db_mysql::print_warnings(
"from [%s] %ld to %ld: %s %s %s\n",
l_time->tm_year + 1900, l_time->tm_mon + 1, l_time->tm_mday,
l_time->tm_hour, l_time->tm_min, l_time->tm_sec,
conn->tgt_host, db_conn->thread_id,
current_thd->thread_id, row[0], row[1], row[2]);
conn->tgt_host, (ulong) db_conn->thread_id,
(ulong) current_thd->thread_id, row[0], row[1], row[2]);
row = mysql_fetch_row(res);
}
if (res)

View file

@ -41,7 +41,6 @@
#include "spd_direct_sql.h"
#include "spd_malloc.h"
ulong *spd_db_att_thread_id;
#ifdef SPIDER_XID_USES_xid_cache_iterate
#else
#ifdef XID_CACHE_IS_SPLITTED
@ -6327,8 +6326,6 @@ int spider_db_init(
#ifdef _WIN32
HMODULE current_module = GetModuleHandle(NULL);
spd_db_att_thread_id = (ulong *)
GetProcAddress(current_module, "?thread_id@@3KA");
#ifdef SPIDER_XID_USES_xid_cache_iterate
#else
#ifdef XID_CACHE_IS_SPLITTED
@ -6362,7 +6359,6 @@ int spider_db_init(
spd_abort_loop = (bool volatile *)
GetProcAddress(current_module, "?abort_loop@@3_NC");
#else
spd_db_att_thread_id = &thread_id;
#ifdef SPIDER_XID_USES_xid_cache_iterate
#else
#ifdef XID_CACHE_IS_SPLITTED