summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/mysqld--help.result5
-rw-r--r--mysql-test/suite/sys_vars/r/thread_cache_size_basic.result14
-rw-r--r--mysql-test/suite/sys_vars/t/thread_cache_size_basic-master.opt1
-rw-r--r--sql/mysqld.cc16
-rw-r--r--sql/sql_const.h2
-rw-r--r--sql/sys_vars.cc4
6 files changed, 30 insertions, 12 deletions
diff --git a/mysql-test/r/mysqld--help.result b/mysql-test/r/mysqld--help.result
index cf6e51e4a35..7cac610f88d 100644
--- a/mysql-test/r/mysqld--help.result
+++ b/mysql-test/r/mysqld--help.result
@@ -1068,7 +1068,8 @@ The following options may be given as the first argument:
Decision to use in heuristic recover process. One of:
COMMIT, ROLLBACK
--thread-cache-size=#
- How many threads we should keep in a cache for reuse
+ How many threads we should keep in a cache for reuse.
+ These are freed after 5 minutes of idle time
--thread-pool-idle-timeout=#
Timeout in seconds for an idle thread in the thread
pool.Worker thread will be shut down after timeout
@@ -1426,7 +1427,7 @@ table-cache 431
table-definition-cache 400
table-open-cache 431
tc-heuristic-recover COMMIT
-thread-cache-size 0
+thread-cache-size 151
thread-pool-idle-timeout 60
thread-pool-max-threads 1000
thread-pool-oversubscribe 3
diff --git a/mysql-test/suite/sys_vars/r/thread_cache_size_basic.result b/mysql-test/suite/sys_vars/r/thread_cache_size_basic.result
index af6777fcf45..a50785c42b7 100644
--- a/mysql-test/suite/sys_vars/r/thread_cache_size_basic.result
+++ b/mysql-test/suite/sys_vars/r/thread_cache_size_basic.result
@@ -1,24 +1,24 @@
SET @start_global_value = @@global.thread_cache_size;
SELECT @start_global_value;
@start_global_value
-0
+256
select @@global.thread_cache_size;
@@global.thread_cache_size
-0
+256
select @@session.thread_cache_size;
ERROR HY000: Variable 'thread_cache_size' is a GLOBAL variable
show global variables like 'thread_cache_size';
Variable_name Value
-thread_cache_size 0
+thread_cache_size 256
show session variables like 'thread_cache_size';
Variable_name Value
-thread_cache_size 0
+thread_cache_size 256
select * from information_schema.global_variables where variable_name='thread_cache_size';
VARIABLE_NAME VARIABLE_VALUE
-THREAD_CACHE_SIZE 0
+THREAD_CACHE_SIZE 256
select * from information_schema.session_variables where variable_name='thread_cache_size';
VARIABLE_NAME VARIABLE_VALUE
-THREAD_CACHE_SIZE 0
+THREAD_CACHE_SIZE 256
set global thread_cache_size=1;
select @@global.thread_cache_size;
@@global.thread_cache_size
@@ -51,4 +51,4 @@ select @@global.thread_cache_size;
SET @@global.thread_cache_size = @start_global_value;
SELECT @@global.thread_cache_size;
@@global.thread_cache_size
-0
+256
diff --git a/mysql-test/suite/sys_vars/t/thread_cache_size_basic-master.opt b/mysql-test/suite/sys_vars/t/thread_cache_size_basic-master.opt
new file mode 100644
index 00000000000..f28fc33b28b
--- /dev/null
+++ b/mysql-test/suite/sys_vars/t/thread_cache_size_basic-master.opt
@@ -0,0 +1 @@
+--max-connections=1024
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 4463c1d891c..acca5749c42 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -2995,6 +2995,7 @@ void unlink_thd(THD *thd)
static bool cache_thread()
{
+ struct timespec abstime;
DBUG_ENTER("cache_thread");
mysql_mutex_lock(&LOCK_thread_cache);
@@ -3013,8 +3014,21 @@ static bool cache_thread()
PSI_THREAD_CALL(delete_current_thread)();
#endif
+ set_timespec(abstime, THREAD_CACHE_TIMEOUT);
while (!abort_loop && ! wake_thread && ! kill_cached_threads)
- mysql_cond_wait(&COND_thread_cache, &LOCK_thread_cache);
+ {
+ int error= mysql_cond_timedwait(&COND_thread_cache, &LOCK_thread_cache,
+ &abstime);
+ if (error == ETIMEDOUT || error == ETIME)
+ {
+ /*
+ If timeout, end thread.
+ If a new thread is requested (wake_thread is set), we will handle
+ the call, even if we got a timeout (as we are already awake and free)
+ */
+ break;
+ }
+ }
cached_thread_count--;
if (kill_cached_threads)
mysql_cond_signal(&COND_flush_thread_cache);
diff --git a/sql/sql_const.h b/sql/sql_const.h
index 76e47bd278b..31ee4603dc9 100644
--- a/sql/sql_const.h
+++ b/sql/sql_const.h
@@ -235,6 +235,8 @@
that does not respond to "initial server greeting" timely
*/
#define CONNECT_TIMEOUT 10
+ /* Wait 5 minutes before removing thread from thread cache */
+#define THREAD_CACHE_TIMEOUT 5*60
/* The following can also be changed from the command line */
#define DEFAULT_CONCURRENCY 10
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 4333edd6bc0..86a3822b2ec 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -3194,9 +3194,9 @@ static Sys_var_ulong Sys_table_cache_size(
static Sys_var_ulong Sys_thread_cache_size(
"thread_cache_size",
- "How many threads we should keep in a cache for reuse",
+ "How many threads we should keep in a cache for reuse. These are freed after 5 minutes of idle time",
GLOBAL_VAR(thread_cache_size), CMD_LINE(REQUIRED_ARG),
- VALID_RANGE(0, 16384), DEFAULT(0), BLOCK_SIZE(1));
+ VALID_RANGE(0, 16384), DEFAULT(256), BLOCK_SIZE(1));
#ifdef HAVE_POOL_OF_THREADS
static bool fix_tp_max_threads(sys_var *, THD *, enum_var_type)