Skip to content

Commit fd9f163

Browse files
committed
MDEV-5205 - MariaDB does not start if more than 128 cpu's are available
- thread_pool_size command line option upper limit increased to 100 000 (same as for max_connections) - thread_pool_size system variable upper limit is maximum of 128 or the value given at command line - thread groups are now allocated dynamically Different limit for command line option and system variable was done to avoid additional mutex for all_groups and threadpool_max_size.
1 parent 52dea41 commit fd9f163

10 files changed

+64
-9
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
SELECT @@global.thread_pool_size;
2+
@@global.thread_pool_size
3+
200
4+
SET @@global.thread_pool_size=150;
5+
SET @@global.thread_pool_size=200;
6+
SET @@global.thread_pool_size=201;
7+
Warnings:
8+
Warning 1292 Truncated incorrect thread_pool_size value: '201'
9+
SELECT @@global.thread_pool_size;
10+
@@global.thread_pool_size
11+
200
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--loose-thread-handling=pool-of-threads

mysql-test/suite/sys_vars/t/thread_pool_size_basic.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# uint global
22
--source include/not_windows.inc
33
--source include/not_embedded.inc
4+
--source include/have_pool_of_threads.inc
45
SET @start_global_value = @@global.thread_pool_size;
56

67
#
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--loose-thread-handling=pool-of-threads --loose-thread-pool-size=200
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--source include/not_windows.inc
2+
--source include/not_embedded.inc
3+
--source include/have_pool_of_threads.inc
4+
5+
SELECT @@global.thread_pool_size;
6+
7+
# Set lower value
8+
SET @@global.thread_pool_size=150;
9+
# Set original value
10+
SET @@global.thread_pool_size=200;
11+
# Try higher value
12+
SET @@global.thread_pool_size=201;
13+
14+
SELECT @@global.thread_pool_size;

sql/sql_plist.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class I_P_List : public C, public I
7575
*/
7676
public:
7777
I_P_List() : I(&m_first), m_first(NULL) {};
78+
/*
79+
empty() is used in many places in the code instead of a constructor, to
80+
initialize a bzero-ed I_P_List instance.
81+
*/
82+
7883
inline void empty() { m_first= NULL; C::reset(); I::set_last(&m_first); }
7984
inline bool is_empty() const { return (m_first == NULL); }
8085
inline void push_front(T* a)

sql/sys_vars.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2298,6 +2298,18 @@ static bool fix_tp_min_threads(sys_var *, THD *, enum_var_type)
22982298

22992299

23002300
#ifndef _WIN32
2301+
static bool check_threadpool_size(sys_var *self, THD *thd, set_var *var)
2302+
{
2303+
ulonglong v= var->save_result.ulonglong_value;
2304+
if (v > threadpool_max_size)
2305+
{
2306+
var->save_result.ulonglong_value= threadpool_max_size;
2307+
return throw_bounds_warning(thd, self->name.str, true, true, v);
2308+
}
2309+
return false;
2310+
}
2311+
2312+
23012313
static bool fix_threadpool_size(sys_var*, THD*, enum_var_type)
23022314
{
23032315
tp_set_threadpool_size(threadpool_size);
@@ -2342,7 +2354,7 @@ static Sys_var_uint Sys_threadpool_size(
23422354
"executing threads (threads in a waiting state do not count as executing).",
23432355
GLOBAL_VAR(threadpool_size), CMD_LINE(REQUIRED_ARG),
23442356
VALID_RANGE(1, MAX_THREAD_GROUPS), DEFAULT(my_getncpus()), BLOCK_SIZE(1),
2345-
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2357+
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_threadpool_size),
23462358
ON_UPDATE(fix_threadpool_size)
23472359
);
23482360
static Sys_var_uint Sys_threadpool_stall_limit(

sql/threadpool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
along with this program; if not, write to the Free Software
1414
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
1515

16-
#define MAX_THREAD_GROUPS 128
16+
#define MAX_THREAD_GROUPS 100000
1717

1818
/* Threadpool parameters */
1919
extern uint threadpool_min_threads; /* Minimum threads in pool */
2020
extern uint threadpool_idle_timeout; /* Shutdown idle worker threads after this timeout */
2121
extern uint threadpool_size; /* Number of parallel executing threads */
22+
extern uint threadpool_max_size;
2223
extern uint threadpool_stall_limit; /* time interval in 10 ms units for stall checks*/
2324
extern uint threadpool_max_threads; /* Maximum threads in pool */
2425
extern uint threadpool_oversubscribe; /* Maximum active threads in group */

sql/threadpool_common.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
uint threadpool_min_threads;
3131
uint threadpool_idle_timeout;
3232
uint threadpool_size;
33+
uint threadpool_max_size;
3334
uint threadpool_stall_limit;
3435
uint threadpool_max_threads;
3536
uint threadpool_oversubscribe;

sql/threadpool_unix.cc

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct thread_group_t
147147

148148
} MY_ALIGNED(512);
149149

150-
static thread_group_t all_groups[MAX_THREAD_GROUPS];
150+
static thread_group_t *all_groups;
151151
static uint group_count;
152152

153153
/**
@@ -517,7 +517,7 @@ static void* timer_thread(void *param)
517517
timer->current_microtime= microsecond_interval_timer();
518518

519519
/* Check stalls in thread groups */
520-
for(i=0; i< array_elements(all_groups);i++)
520+
for (i= 0; i < threadpool_max_size; i++)
521521
{
522522
if(all_groups[i].connection_count)
523523
check_stall(&all_groups[i]);
@@ -907,6 +907,7 @@ int thread_group_init(thread_group_t *thread_group, pthread_attr_t* thread_attr)
907907
thread_group->pollfd= -1;
908908
thread_group->shutdown_pipe[0]= -1;
909909
thread_group->shutdown_pipe[1]= -1;
910+
thread_group->queue.empty();
910911
DBUG_RETURN(0);
911912
}
912913

@@ -1510,10 +1511,18 @@ static void *worker_main(void *param)
15101511
bool tp_init()
15111512
{
15121513
DBUG_ENTER("tp_init");
1514+
threadpool_max_size= max(threadpool_size, 128);
1515+
all_groups= (thread_group_t *)
1516+
my_malloc(sizeof(thread_group_t) * threadpool_max_size, MYF(MY_WME|MY_ZEROFILL));
1517+
if (!all_groups)
1518+
{
1519+
threadpool_max_size= 0;
1520+
DBUG_RETURN(1);
1521+
}
15131522
threadpool_started= true;
15141523
scheduler_init();
15151524

1516-
for(uint i=0; i < array_elements(all_groups); i++)
1525+
for (uint i= 0; i < threadpool_max_size; i++)
15171526
{
15181527
thread_group_init(&all_groups[i], get_connection_attrib());
15191528
}
@@ -1542,10 +1551,11 @@ void tp_end()
15421551
DBUG_VOID_RETURN;
15431552

15441553
stop_timer(&pool_timer);
1545-
for(uint i=0; i< array_elements(all_groups); i++)
1554+
for (uint i= 0; i < threadpool_max_size; i++)
15461555
{
15471556
thread_group_close(&all_groups[i]);
15481557
}
1558+
my_free(all_groups);
15491559
threadpool_started= false;
15501560
DBUG_VOID_RETURN;
15511561
}
@@ -1604,9 +1614,7 @@ void tp_set_threadpool_stall_limit(uint limit)
16041614
int tp_get_idle_thread_count()
16051615
{
16061616
int sum=0;
1607-
for(uint i= 0;
1608-
i< array_elements(all_groups) && (all_groups[i].pollfd >= 0);
1609-
i++)
1617+
for (uint i= 0; i < threadpool_max_size && all_groups[i].pollfd >= 0; i++)
16101618
{
16111619
sum+= (all_groups[i].thread_count - all_groups[i].active_thread_count);
16121620
}

0 commit comments

Comments
 (0)