mirror of
https://github.com/MariaDB/server.git
synced 2026-05-04 22:25:32 +02:00
Get rid of idle thread counter atomic variable.
Instead, use function that loops over groups and calculates idle threads for "show status".
This commit is contained in:
parent
18c9b345b4
commit
d212991e89
4 changed files with 53 additions and 23 deletions
|
|
@ -7008,6 +7008,15 @@ static int show_default_keycache(THD *thd, SHOW_VAR *var, char *buff)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_POOL_OF_THREADS
|
||||
int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff)
|
||||
{
|
||||
var->type= SHOW_INT;
|
||||
var->value= buff;
|
||||
*(int *)buff= tp_get_idle_thread_count();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
Variables shown by SHOW STATUS in alphabetical order
|
||||
|
|
@ -7144,8 +7153,8 @@ SHOW_VAR status_vars[]= {
|
|||
{"Tc_log_page_size", (char*) &tc_log_page_size, SHOW_LONG},
|
||||
{"Tc_log_page_waits", (char*) &tc_log_page_waits, SHOW_LONG},
|
||||
#endif
|
||||
#ifndef EMBEDDED_LIBRARY
|
||||
{"Threadpool_idle_threads", (char *) &tp_stats.num_waiting_threads, SHOW_INT},
|
||||
#ifdef HAVE_POOL_OF_THREADS
|
||||
{"Threadpool_idle_threads", (char *) &show_threadpool_idle_threads, SHOW_FUNC},
|
||||
{"Threadpool_threads", (char *) &tp_stats.num_worker_threads, SHOW_INT},
|
||||
#endif
|
||||
{"Threads_cached", (char*) &cached_thread_count, SHOW_LONG_NOFLUSH},
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ extern void tp_wait_end(THD*);
|
|||
extern void tp_post_kill_notification(THD *thd);
|
||||
extern void tp_end(void);
|
||||
|
||||
/* Used in SHOW for threadpool_idle_thread_count */
|
||||
extern int tp_get_idle_thread_count();
|
||||
|
||||
/*
|
||||
Threadpool statistics
|
||||
*/
|
||||
|
|
@ -29,8 +32,6 @@ struct TP_STATISTICS
|
|||
{
|
||||
/* Current number of worker thread. */
|
||||
volatile int32 num_worker_threads;
|
||||
/* Current number of idle threads. */
|
||||
volatile int32 num_waiting_threads;
|
||||
};
|
||||
|
||||
extern TP_STATISTICS tp_stats;
|
||||
|
|
@ -45,3 +46,5 @@ extern void tp_set_threadpool_stall_limit(uint val);
|
|||
/* Activate threadpool scheduler */
|
||||
extern void tp_scheduler(void);
|
||||
|
||||
extern int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff);
|
||||
|
||||
|
|
|
|||
|
|
@ -384,18 +384,6 @@ static connection_t *queue_get(thread_group_t *thread_group)
|
|||
}
|
||||
|
||||
|
||||
static void increment_active_threads(thread_group_t *thread_group)
|
||||
{
|
||||
my_atomic_add32(&tp_stats.num_waiting_threads,-1);
|
||||
thread_group->active_thread_count++;
|
||||
}
|
||||
|
||||
static void decrement_active_threads(thread_group_t *thread_group)
|
||||
{
|
||||
my_atomic_add32(&tp_stats.num_waiting_threads,1);
|
||||
thread_group->active_thread_count--;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Handle wait timeout :
|
||||
|
|
@ -585,7 +573,7 @@ static connection_t * listener(worker_thread_t *current_thread,
|
|||
|
||||
connection_t *retval= NULL;
|
||||
|
||||
decrement_active_threads(thread_group);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
native_event ev[MAX_EVENTS];
|
||||
|
|
@ -594,7 +582,9 @@ static connection_t * listener(worker_thread_t *current_thread,
|
|||
if (thread_group->shutdown)
|
||||
break;
|
||||
|
||||
thread_group->active_thread_count--;
|
||||
cnt = io_poll_wait(thread_group->pollfd, ev, MAX_EVENTS, -1);
|
||||
thread_group->active_thread_count++;
|
||||
|
||||
if (cnt <=0)
|
||||
{
|
||||
|
|
@ -705,7 +695,7 @@ static connection_t * listener(worker_thread_t *current_thread,
|
|||
}
|
||||
}
|
||||
|
||||
increment_active_threads(thread_group);
|
||||
|
||||
DBUG_RETURN(retval);
|
||||
}
|
||||
|
||||
|
|
@ -1037,12 +1027,12 @@ connection_t *get_event(worker_thread_t *current_thread,
|
|||
*/
|
||||
thread_group->waiting_threads.push_front(current_thread);
|
||||
|
||||
decrement_active_threads(thread_group);
|
||||
thread_group->active_thread_count--;
|
||||
if(abstime)
|
||||
err = mysql_cond_timedwait(¤t_thread->cond, &thread_group->mutex, abstime);
|
||||
else
|
||||
err = mysql_cond_wait(¤t_thread->cond, &thread_group->mutex);
|
||||
increment_active_threads(thread_group);
|
||||
thread_group->active_thread_count++;
|
||||
|
||||
if (!current_thread->woken)
|
||||
{
|
||||
|
|
@ -1076,7 +1066,8 @@ void wait_begin(thread_group_t *thread_group)
|
|||
{
|
||||
DBUG_ENTER("wait_begin");
|
||||
mysql_mutex_lock(&thread_group->mutex);
|
||||
decrement_active_threads(thread_group);
|
||||
thread_group->active_thread_count--;
|
||||
|
||||
DBUG_ASSERT(thread_group->active_thread_count >=0);
|
||||
DBUG_ASSERT(thread_group->connection_count > 0);
|
||||
|
||||
|
|
@ -1102,7 +1093,7 @@ void wait_end(thread_group_t *thread_group)
|
|||
{
|
||||
DBUG_ENTER("wait_end");
|
||||
mysql_mutex_lock(&thread_group->mutex);
|
||||
increment_active_threads(thread_group);
|
||||
thread_group->active_thread_count++;
|
||||
mysql_mutex_unlock(&thread_group->mutex);
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
|
@ -1525,3 +1516,20 @@ void tp_set_threadpool_stall_limit(uint limit)
|
|||
mysql_cond_signal(&(pool_timer.cond));
|
||||
mysql_mutex_unlock(&(pool_timer.mutex));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Calculate number of idle/waiting threads in the pool.
|
||||
|
||||
Sum idle threads over all groups.
|
||||
Don't do any locking, it is not required for stats.
|
||||
*/
|
||||
int tp_get_idle_thread_count()
|
||||
{
|
||||
int sum=0;
|
||||
for(uint i= 0; i< array_elements(all_groups) && (all_groups[i].pollfd >= 0); i++)
|
||||
{
|
||||
sum+= (all_groups[i].thread_count - all_groups[i].active_thread_count);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
|
@ -753,3 +753,13 @@ void tp_wait_end(THD *thd)
|
|||
/* Do we need to do anything ? */
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Number of idle threads in pool.
|
||||
This info is not available in Windows implementation,
|
||||
thus function always returns 0.
|
||||
*/
|
||||
int tp_get_idle_thread_count()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue