summaryrefslogtreecommitdiff
path: root/sql/threadpool_unix.cc
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2016-02-01 12:45:39 +0200
committerMonty <monty@mariadb.org>2016-02-07 10:34:03 +0200
commit3d4a7390c1a94ef6e07b04b52ea94a95878cda1b (patch)
treea53179de37b318e27e48546ed3bc8a723148104a /sql/threadpool_unix.cc
parent076aa182c2d2ee67c233d0e79c900dfba6f593c1 (diff)
downloadmariadb-git-3d4a7390c1a94ef6e07b04b52ea94a95878cda1b.tar.gz
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)
Diffstat (limited to 'sql/threadpool_unix.cc')
-rw-r--r--sql/threadpool_unix.cc74
1 files changed, 44 insertions, 30 deletions
diff --git a/sql/threadpool_unix.cc b/sql/threadpool_unix.cc
index 89a2036cb10..684b074f9f0 100644
--- a/sql/threadpool_unix.cc
+++ b/sql/threadpool_unix.cc
@@ -809,7 +809,7 @@ static int create_worker(thread_group_t *thread_group)
if (!err)
{
thread_group->last_thread_creation_time=microsecond_interval_timer();
- thread_created++;
+ statistic_increment(thread_created,&LOCK_status);
add_thread_count(thread_group, 1);
}
else
@@ -1203,14 +1203,14 @@ void wait_end(thread_group_t *thread_group)
Allocate/initialize a new connection structure.
*/
-connection_t *alloc_connection(THD *thd)
+connection_t *alloc_connection()
{
+ connection_t* connection;
DBUG_ENTER("alloc_connection");
+ DBUG_EXECUTE_IF("simulate_failed_connection_1", DBUG_RETURN(0); );
- connection_t* connection = (connection_t *)my_malloc(sizeof(connection_t),0);
- if (connection)
+ if ((connection = (connection_t *)my_malloc(sizeof(connection_t),0)))
{
- connection->thd = thd;
connection->waiting= false;
connection->logged_in= false;
connection->bound_to_poll_descriptor= false;
@@ -1225,38 +1225,40 @@ connection_t *alloc_connection(THD *thd)
Add a new connection to thread pool..
*/
-void tp_add_connection(THD *thd)
+void tp_add_connection(CONNECT *connect)
{
+ connection_t *connection;
+ THD *thd;
DBUG_ENTER("tp_add_connection");
-
- threads.append(thd);
- mysql_mutex_unlock(&LOCK_thread_count);
- connection_t *connection= alloc_connection(thd);
- if (connection)
+
+ if (!(connection= alloc_connection()) || !(thd= connect->create_thd()))
{
- thd->event_scheduler.data= connection;
+ my_free(connection);
+ connect->close_and_delete();
+ DBUG_VOID_RETURN;
+ }
+ connection->thd= thd;
+ delete connect;
+
+ add_to_active_threads(thd);
+
+ thd->event_scheduler.data= connection;
- /* Assign connection to a group. */
- thread_group_t *group=
- &all_groups[thd->thread_id%group_count];
+ /* Assign connection to a group. */
+ thread_group_t *group=
+ &all_groups[thd->thread_id%group_count];
- connection->thread_group=group;
+ connection->thread_group=group;
- mysql_mutex_lock(&group->mutex);
- group->connection_count++;
- mysql_mutex_unlock(&group->mutex);
+ mysql_mutex_lock(&group->mutex);
+ group->connection_count++;
+ mysql_mutex_unlock(&group->mutex);
- /*
- Add connection to the work queue.Actual logon
- will be done by a worker thread.
- */
- queue_put(group, connection);
- }
- else
- {
- /* Allocation failed */
- threadpool_cleanup_connection(thd);
- }
+ /*
+ Add connection to the work queue.Actual logon
+ will be done by a worker thread.
+ */
+ queue_put(group, connection);
DBUG_VOID_RETURN;
}
@@ -1549,6 +1551,18 @@ bool tp_init()
}
+/* Dummy functions, do nothing */
+
+bool tp_init_new_connection_thread()
+{
+ return 0;
+}
+
+bool tp_end_thread(THD *thd, bool cache_thread)
+{
+ return 0;
+}
+
void tp_end()
{
DBUG_ENTER("tp_end");