diff options
author | Monty <monty@mariadb.org> | 2016-02-01 12:45:39 +0200 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2016-02-07 10:34:03 +0200 |
commit | 3d4a7390c1a94ef6e07b04b52ea94a95878cda1b (patch) | |
tree | a53179de37b318e27e48546ed3bc8a723148104a /sql/threadpool_win.cc | |
parent | 076aa182c2d2ee67c233d0e79c900dfba6f593c1 (diff) | |
download | mariadb-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_win.cc')
-rw-r--r-- | sql/threadpool_win.cc | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/sql/threadpool_win.cc b/sql/threadpool_win.cc index 4be51f3d6e9..e036bd614fd 100644 --- a/sql/threadpool_win.cc +++ b/sql/threadpool_win.cc @@ -230,7 +230,7 @@ struct connection_t }; -void init_connection(connection_t *connection) +void init_connection(connection_t *connection, THD *thd) { connection->logged_in = false; connection->handle= 0; @@ -243,7 +243,8 @@ void init_connection(connection_t *connection) memset(&connection->overlapped, 0, sizeof(OVERLAPPED)); InitializeThreadpoolEnvironment(&connection->callback_environ); SetThreadpoolCallbackPool(&connection->callback_environ, pool); - connection->thd = 0; + connection->thd = thd; + thd->event_scheduler.data= connection; } @@ -465,7 +466,7 @@ static void check_thread_init() if (FlsGetValue(fls) == NULL) { FlsSetValue(fls, (void *)1); - thread_created++; + statistic_increment(thread_created, &LOCK_status); InterlockedIncrement((volatile long *)&tp_stats.num_worker_threads); } } @@ -532,6 +533,16 @@ bool tp_init(void) } +/* Dummy functions, do nothing */ + +bool tp_init_new_connection_thread() +{ + return 0; +} + +bool tp_end_thread(THD *thd, bool cache_thread) +{} + /** Scheduler callback : Destroy the scheduler. */ @@ -544,7 +555,6 @@ void tp_end(void) } } - /* Handle read completion/notification. */ @@ -656,24 +666,26 @@ static void CALLBACK shm_read_callback(PTP_CALLBACK_INSTANCE instance, /* Notify the thread pool about a new connection. - NOTE: LOCK_thread_count is locked on entry. This function must unlock it. */ -void tp_add_connection(THD *thd) + +void tp_add_connection(CONNECT *connect) { - threads.append(thd); - mysql_mutex_unlock(&LOCK_thread_count); + THD *thd; + connection_t *con; - connection_t *con = (connection_t *)malloc(sizeof(connection_t)); - if(!con) + if (!(con = (connection_t *) malloc(sizeof(connection_t))) || + !(thd= connect->create_thd())) { tp_log_warning("Allocation failed", "tp_add_connection"); - threadpool_cleanup_connection(thd); + free(con) + connect->close_and_delete(); return; } + delete connect; + + add_to_active_threads(thd); - init_connection(con); - con->thd= thd; - thd->event_scheduler.data= con; + init_connection(con, thd); /* Try to login asynchronously, using threads in the pool */ PTP_WORK wrk = CreateThreadpoolWork(login_callback,con, &con->callback_environ); |