diff options
author | Vladislav Vaintroub <wlad@montyprogram.com> | 2012-01-15 15:41:25 +0100 |
---|---|---|
committer | Vladislav Vaintroub <wlad@montyprogram.com> | 2012-01-15 15:41:25 +0100 |
commit | d212991e892c366f6df96f8b52c8306ae329770f (patch) | |
tree | c89b92bccb4b1e84cf02db4eb46adae23222d703 | |
parent | 18c9b345b43b62b7c4dbac8ce0289c1c8103c2d1 (diff) | |
download | mariadb-git-d212991e892c366f6df96f8b52c8306ae329770f.tar.gz |
Get rid of idle thread counter atomic variable.
Instead, use function that loops over groups and
calculates idle threads for "show status".
-rw-r--r-- | sql/mysqld.cc | 13 | ||||
-rw-r--r-- | sql/threadpool.h | 7 | ||||
-rw-r--r-- | sql/threadpool_unix.cc | 46 | ||||
-rw-r--r-- | sql/threadpool_win.cc | 10 |
4 files changed, 53 insertions, 23 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc index cc32411e567..78faf5cef76 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -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}, diff --git a/sql/threadpool.h b/sql/threadpool.h index 8c991aab2cb..78112b8b7bc 100644 --- a/sql/threadpool.h +++ b/sql/threadpool.h @@ -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); + diff --git a/sql/threadpool_unix.cc b/sql/threadpool_unix.cc index b6eeb5bcffd..f66c862dd0f 100644 --- a/sql/threadpool_unix.cc +++ b/sql/threadpool_unix.cc @@ -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]; @@ -593,8 +581,10 @@ 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; +}
\ No newline at end of file diff --git a/sql/threadpool_win.cc b/sql/threadpool_win.cc index 0afb628a1ca..1a560e62301 100644 --- a/sql/threadpool_win.cc +++ b/sql/threadpool_win.cc @@ -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; +}
\ No newline at end of file |