diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2019-05-19 02:10:40 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2019-05-21 17:55:09 +0400 |
commit | ebc55c8577be7b8b8c3d9433feb4ce457f5b6cc5 (patch) | |
tree | aa39a653cebe6509fdd00d21dc16098469d6d102 | |
parent | 6900aaf417c6540a22ab74c6badaf42cd37e43e1 (diff) | |
download | mariadb-git-ebc55c8577be7b8b8c3d9433feb4ce457f5b6cc5.tar.gz |
Simplified away scheduler_functions::end_thread()
Code properly integrated into callers instead.
do_handle_one_connection(): no need to reset thd and thd->thread_stack
as they're not updated by cache_thread().
Part of MDEV-19515 - Improve connect speed
-rw-r--r-- | sql/mysqld.cc | 50 | ||||
-rw-r--r-- | sql/mysqld.h | 2 | ||||
-rw-r--r-- | sql/scheduler.cc | 16 | ||||
-rw-r--r-- | sql/scheduler.h | 1 | ||||
-rw-r--r-- | sql/sql_connect.cc | 36 | ||||
-rw-r--r-- | sql/sql_connect.h | 2 | ||||
-rw-r--r-- | sql/threadpool_common.cc | 9 | ||||
-rw-r--r-- | sql/wsrep_mysqld.cc | 4 |
8 files changed, 23 insertions, 97 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 6eb1febdb9c..4218cb5e02f 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2663,7 +2663,7 @@ void unlink_thd(THD *thd) */ -static bool cache_thread(THD *thd) +bool cache_thread(THD *thd) { struct timespec abstime; DBUG_ENTER("cache_thread"); @@ -2748,51 +2748,6 @@ static bool cache_thread(THD *thd) } -/* - End thread for the current connection - - SYNOPSIS - one_thread_per_connection_end() - thd Thread handler. This may be null if we run out of resources. - put_in_cache Store thread in cache, if there is room in it - Normally this is true in all cases except when we got - out of resources initializing the current thread - - NOTES - If thread is cached, we will wait until thread is scheduled to be - reused and then we will return. - If thread is not cached, we end the thread. - - RETURN - 0 Signal to handle_one_connection to reuse connection -*/ - -bool one_thread_per_connection_end(THD *thd, bool put_in_cache) -{ - DBUG_ENTER("one_thread_per_connection_end"); - - if (thd) - { - const bool wsrep_applier= IF_WSREP(thd->wsrep_applier, false); - - unlink_thd(thd); - if (!wsrep_applier && put_in_cache && cache_thread(thd)) - DBUG_RETURN(0); // Thread is reused - delete thd; - } - - DBUG_PRINT("info", ("killing thread")); - DBUG_LEAVE; // Must match DBUG_ENTER() -#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) - ERR_remove_state(0); -#endif - my_thread_end(); - - pthread_exit(0); - return 0; // Avoid compiler warnings -} - - void flush_thread_cache() { DBUG_ENTER("flush_thread_cache"); @@ -6177,8 +6132,7 @@ void inc_thread_created(void) void handle_connection_in_main_thread(CONNECT *connect) { - thread_cache_size= 0; // Safety - do_handle_one_connection(connect); + do_handle_one_connection(connect, false); } diff --git a/sql/mysqld.h b/sql/mysqld.h index f404b11b7b4..ceef0dd7b3a 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -79,7 +79,7 @@ void close_connection(THD *thd, uint sql_errno= 0); void handle_connection_in_main_thread(CONNECT *thd); void create_thread_to_handle_connection(CONNECT *connect); void unlink_thd(THD *thd); -bool one_thread_per_connection_end(THD *thd, bool put_in_cache); +bool cache_thread(THD *thd); void flush_thread_cache(); void refresh_status(THD *thd); bool is_secure_file_path(char *path); diff --git a/sql/scheduler.cc b/sql/scheduler.cc index 59d7c548871..5f24495059f 100644 --- a/sql/scheduler.cc +++ b/sql/scheduler.cc @@ -29,20 +29,6 @@ #include "sql_callback.h" #include <violite.h> -/* - End connection, in case when we are using 'no-threads' -*/ - -static bool no_threads_end(THD *thd, bool put_in_cache) -{ - if (thd) - { - unlink_thd(thd); - delete thd; - } - return 1; // Abort handle_one_connection -} - /** @internal Helper functions to allow mysys to call the thread scheduler when waiting for locks. @@ -133,7 +119,6 @@ void one_thread_per_connection_scheduler(scheduler_functions *func, func->max_connections= arg_max_connections; func->connection_count= arg_connection_count; func->add_connection= create_thread_to_handle_connection; - func->end_thread= one_thread_per_connection_end; func->post_kill_notification= post_kill_notification; } #else @@ -153,5 +138,4 @@ void one_thread_scheduler(scheduler_functions *func) func->max_connections= &max_connections; func->connection_count= &connection_count; func->add_connection= handle_connection_in_main_thread; - func->end_thread= no_threads_end; } diff --git a/sql/scheduler.h b/sql/scheduler.h index 12d54f74c4e..e77d6b5e80c 100644 --- a/sql/scheduler.h +++ b/sql/scheduler.h @@ -38,7 +38,6 @@ struct scheduler_functions void (*thd_wait_begin)(THD *thd, int wait_type); void (*thd_wait_end)(THD *thd); void (*post_kill_notification)(THD *thd); - bool (*end_thread)(THD *thd, bool cache_thread); void (*end)(void); }; diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 3646aee0f03..1485ee9f363 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -1112,7 +1112,6 @@ bool setup_connection_thread_globals(THD *thd) close_connection(thd, ER_OUT_OF_RESOURCES); statistic_increment(aborted_connects,&LOCK_status); statistic_increment(connection_errors_internal, &LOCK_status); - thd->scheduler->end_thread(thd, 0); return 1; // Error } return 0; @@ -1304,14 +1303,15 @@ pthread_handler_t handle_one_connection(void *arg) mysql_thread_set_psi_id(connect->thread_id); if (init_new_connection_handler_thread()) - { - scheduler_functions *scheduler= connect->scheduler; connect->close_with_error(0, 0, ER_OUT_OF_RESOURCES); - scheduler->end_thread(0, 0); - return 0; - } + else + do_handle_one_connection(connect, true); - do_handle_one_connection(connect); + DBUG_PRINT("info", ("killing thread")); +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) + ERR_remove_state(0); +#endif + my_thread_end(); return 0; } @@ -1344,15 +1344,13 @@ bool thd_is_connection_alive(THD *thd) } -void do_handle_one_connection(CONNECT *connect) +void do_handle_one_connection(CONNECT *connect, bool put_in_cache) { ulonglong thr_create_utime= microsecond_interval_timer(); THD *thd; if (!(thd= connect->create_thd(NULL))) { - scheduler_functions *scheduler= connect->scheduler; connect->close_with_error(0, 0, ER_OUT_OF_RESOURCES); - scheduler->end_thread(0, 0); return; } @@ -1388,7 +1386,11 @@ void do_handle_one_connection(CONNECT *connect) */ thd->thread_stack= (char*) &thd; if (setup_connection_thread_globals(thd)) + { + unlink_thd(thd); + delete thd; return; + } for (;;) { @@ -1422,16 +1424,12 @@ end_thread: if (thd->userstat_running) update_global_user_stats(thd, create_user, time(NULL)); - if (thd->scheduler->end_thread(thd, 1)) - return; // Probably no-threads - - /* - If end_thread() returns, this thread has been schedule to - handle the next connection. - */ - thd= current_thd; - thd->thread_stack= (char*) &thd; + unlink_thd(thd); + if (IF_WSREP(thd->wsrep_applier, false) || !put_in_cache || + !cache_thread(thd)) + break; } + delete thd; } #endif /* EMBEDDED_LIBRARY */ diff --git a/sql/sql_connect.h b/sql/sql_connect.h index 8b574bcf385..544270189db 100644 --- a/sql/sql_connect.h +++ b/sql/sql_connect.h @@ -73,7 +73,7 @@ void free_global_index_stats(void); void free_global_client_stats(void); pthread_handler_t handle_one_connection(void *arg); -void do_handle_one_connection(CONNECT *connect); +void do_handle_one_connection(CONNECT *connect, bool put_in_cache); bool init_new_connection_handler_thread(); void reset_mqh(LEX_USER *lu, bool get_them); bool check_mqh(THD *thd, uint check_command); diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc index 042814a8321..66f7a94d528 100644 --- a/sql/threadpool_common.cc +++ b/sql/threadpool_common.cc @@ -380,14 +380,6 @@ end: } - -/* Dummy functions, do nothing */ - -static bool tp_end_thread(THD *, bool) -{ - return 0; -} - static TP_pool *pool; static bool tp_init() @@ -511,7 +503,6 @@ static scheduler_functions tp_scheduler_functions= tp_wait_begin, // thd_wait_begin tp_wait_end, // thd_wait_end tp_post_kill_notification, // post kill notification - tp_end_thread, // Dummy function tp_end // end }; diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index a278820efb6..63b8974734e 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -2638,7 +2638,7 @@ void* start_wsrep_THD(void *arg) { close_connection(thd, ER_OUT_OF_RESOURCES); statistic_increment(aborted_connects,&LOCK_status); - MYSQL_CALLBACK(thread_scheduler, end_thread, (thd, 0)); + unlink_thd(thd); delete thd; delete thd_args; goto error; @@ -2685,7 +2685,7 @@ void* start_wsrep_THD(void *arg) if (plugins_are_initialized) { net_end(&thd->net); - MYSQL_CALLBACK(thread_scheduler, end_thread, (thd, 1)); + unlink_thd(thd); } else { |