summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2019-04-15 12:28:10 +0100
committerVladislav Vaintroub <wlad@mariadb.com>2019-04-15 12:28:10 +0100
commit892529ec09055921f17ec38e52586703a96b8fdf (patch)
treed08260d82fcafa05a9aa956d79e09ce7c970f60d
parent4ac8fa008dc55879060be7c4653b2e634f0162be (diff)
downloadmariadb-git-bb-10.2-snow-threadpool.tar.gz
threadpool : Make throttling interval depend on thread_pool_stall_limitbb-10.2-snow-threadpool
A thread_pool_stall_limit which is smaller than default would result in quicker creation of threads.
-rw-r--r--sql/sys_vars.cc2
-rw-r--r--sql/threadpool.h3
-rw-r--r--sql/threadpool_generic.cc20
3 files changed, 14 insertions, 11 deletions
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 2a793646c7f..fe0cfdf6d6e 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -3414,7 +3414,7 @@ static Sys_var_uint Sys_threadpool_stall_limit(
"If a worker thread is stalled, additional worker thread "
"may be created to handle remaining clients.",
GLOBAL_VAR(threadpool_stall_limit), CMD_LINE(REQUIRED_ARG),
- VALID_RANGE(10, UINT_MAX), DEFAULT(500), BLOCK_SIZE(1),
+ VALID_RANGE(1, UINT_MAX), DEFAULT(DEFAULT_THREADPOOL_STALL_LIMIT), BLOCK_SIZE(1),
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
ON_UPDATE(fix_threadpool_stall_limit)
);
diff --git a/sql/threadpool.h b/sql/threadpool.h
index ba17dc042c2..561c4f3e086 100644
--- a/sql/threadpool.h
+++ b/sql/threadpool.h
@@ -20,7 +20,7 @@ extern uint threadpool_min_threads; /* Minimum threads in pool */
extern uint threadpool_idle_timeout; /* Shutdown idle worker threads after this timeout */
extern uint threadpool_size; /* Number of parallel executing threads */
extern uint threadpool_max_size;
-extern uint threadpool_stall_limit; /* time interval in 10 ms units for stall checks*/
+extern uint threadpool_stall_limit; /* time interval in milliseconds for stall checks*/
extern uint threadpool_max_threads; /* Maximum threads in pool */
extern uint threadpool_oversubscribe; /* Maximum active threads in group */
extern uint threadpool_prio_kickup_timer; /* Time before low prio item gets prio boost */
@@ -30,6 +30,7 @@ extern uint threadpool_mode; /* Thread pool implementation , windows or generic
#define TP_MODE_GENERIC 1
#endif
+#define DEFAULT_THREADPOOL_STALL_LIMIT 500U
struct TP_connection;
extern void tp_callback(TP_connection *c);
diff --git a/sql/threadpool_generic.cc b/sql/threadpool_generic.cc
index 400d072df3c..e630b5b5782 100644
--- a/sql/threadpool_generic.cc
+++ b/sql/threadpool_generic.cc
@@ -19,6 +19,7 @@
#include <sql_class.h>
#include <my_pthread.h>
#include <scheduler.h>
+#include <algorithm> /* std::max*/
#ifdef HAVE_POOL_OF_THREADS
@@ -984,23 +985,24 @@ end:
The actual values were not calculated using any scientific methods.
They just look right, and behave well in practice.
-
- TODO: Should throttling depend on thread_pool_stall_limit?
*/
+
+#define THROTTLING_FACTOR (threadpool_stall_limit/std::max(DEFAULT_THREADPOOL_STALL_LIMIT,threadpool_stall_limit))
+
static ulonglong microsecond_throttling_interval(thread_group_t *thread_group)
{
int count= thread_group->thread_count;
- if (count < 4)
+ if (count < 1+ (int)threadpool_oversubscribe)
return 0;
-
+
if (count < 8)
- return 50*1000;
-
+ return 50*1000*THROTTLING_FACTOR;
+
if(count < 16)
- return 100*1000;
-
- return 200*1000;
+ return 100*1000*THROTTLING_FACTOR;
+
+ return 200*100*THROTTLING_FACTOR;
}