summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2016-03-22 23:42:13 +0200
committerMonty <monty@mariadb.org>2016-03-22 23:44:52 +0200
commitfa3edbf40d6b9f6b56feaceb0ec90753f1072ac9 (patch)
tree15a7261c4e79e0871901321bd2e78e588c7a0394 /sql
parent260dd476b057b759af7973550b560dc2f56e18fd (diff)
downloadmariadb-git-fa3edbf40d6b9f6b56feaceb0ec90753f1072ac9.tar.gz
Increase value of thread_cache_size to 32
Added 5 minute timeout before automaticlally removing threads from thread cache. This solves a problem with jemalloc, which is slow with a small thread cache and also makes thread_cache big enough that most users doesn't have to touch it
Diffstat (limited to 'sql')
-rw-r--r--sql/mysqld.cc16
-rw-r--r--sql/sql_const.h2
-rw-r--r--sql/sys_vars.cc4
3 files changed, 19 insertions, 3 deletions
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)