MySQL數據庫線程緩沖池的相關知識是本文我們主要要介紹的內容
在一個連接斷開時
static bool cache_thread()
{
safe_mutex_assert_owner(&LOCK_thread_count);
if (
cached_thread_count < thread_cache_size
&&
! abort_loop && !kill_cached_threads)
{
/* Don
DBUG_PRINT("info"
cached_thread_count++;
while (!abort_loop && ! wake_thread && ! kill_cached_threads)
(void) pthread_cond_wait(&COND_thread_cache
cached_thread_count
if (kill_cached_threads)
pthread_cond_signal(&COND_flush_thread_cache);
if (wake_thread)
{
THD *thd;
wake_thread
thd= thread_cache
thd
(void) thd
/*
THD::mysys_var::abort is associated with physical thread rather
than with THD object
this thread for handling of new THD object/connection
*/
thd
thd
threads
return(
}
}
return(
}
上面我們的啟動參數設置線程緩沖區為
了此刻cache中的空閒線程數目
程掛起
如下
int pthread_cond_timedwait(pthread_cond_t *cond
struct timespec *abstime)
int result;
long timeout;
union ft
if( abstime != NULL )
{
GetSystemTimeAsFileTime(&now
/*
Calculate time left to abstime
*/
timeout= (long)((abstime
/* Don
if (timeout <
timeout=
/*
Make sure the calucated timeout does not exceed original timeout
value which could cause "wait for ever" if system time changes
*/
if (timeout > abstime
timeout= abstime
}
else
{
/* No time specified; don
timeout= INFINITE;
}
/*
Block access if previous broadcast hasn
This is just for safety and should normally not
affect the total time spent in this function
*/
WaitForSingleObject(cond
EnterCriticalSection(&cond
cond
LeaveCriticalSection(&cond
LeaveCriticalSection(mutex);
result= WaitForMultipleObjects(
EnterCriticalSection(&cond
cond
if (cond
{
/*
We
reset the manual event
*/
/* Close broadcast gate */
ResetEvent(cond
/* Open block gate */
SetEvent(cond
}
LeaveCriticalSection(&cond
EnterCriticalSection(mutex);
return result == WAIT_TIMEOUT ? ETIMEDOUT :
}
此處是等待時間
void create_thread_to_handle_connection(THD *thd)
{
if (cached_thread_count > wake_thread)
{
/* Get thread from cache */
thread_cache
wake_thread++;
pthread_cond_signal(&COND_thread_cache);
}
Else
}
關於MySQL數據庫線程緩沖池的相關知識就介紹到這裡了
From:http://tw.wingwit.com/Article/program/MySQL/201311/29579.html