當(dāng)客戶端向服務(wù)器發(fā)起查詢時(shí),就是和服務(wù)器之間建立了一個(gè)連接。而MySQL是提供了一個(gè)最大連接數(shù)限制的。所以,每次在一個(gè)連接建立
當(dāng)客戶端向服務(wù)器發(fā)起查詢時(shí),,就是和服務(wù)器之間建立了一個(gè)連接。而MySQL是提供了一個(gè)最大連接數(shù)限制的。所以,每次在一個(gè)連接建立成功后,服務(wù)器要給該連接分配處理線程的時(shí)候會(huì)判斷現(xiàn)在的連接數(shù)是否已經(jīng)操作了配置的最大連接數(shù)了。如果已經(jīng)超過,則不會(huì)再分配線程來處理,直接關(guān)閉在連接。
static void create_new_thread(THD *thd)
{
DBUG_ENTER("create_new_thread");
/*
Don't allow too many connections. We roughly check here that we allow
only (max_connections + 1) connections.
*/
mysql_mutex_lock(&LOCK_connection_count);
if (connection_count >= max_connections + 1 || abort_loop)
{//判斷是否超過最大連接或是否標(biāo)志終止,該最大連接是在my.ini文件中配置的,
mysql_mutex_unlock(&LOCK_connection_count);
DBUG_PRINT("error",("Too many connections"));
close_connection(thd, ER_CON_COUNT_ERROR);
delete thd;
DBUG_VOID_RETURN;
}
++connection_count;//如果沒有,增加連接數(shù)
if (connection_count > max_used_connections)
max_used_connections= connection_count;//增加最大使用連接數(shù)
mysql_mutex_unlock(&LOCK_connection_count);
/* Start a new thread to handle connection. */
mysql_mutex_lock(&LOCK_thread_count);
/*
The initialization of thread_id is done in create_embedded_thd() for
the embedded library.
TODO: refactor this to avoid code duplication there
*/
thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
thread_count++;//增加線程數(shù),準(zhǔn)備為該連接分配線程了(見面的函數(shù))
MYSQL_CALLBACK(thread_scheduler, add_connection, (thd));
DBUG_VOID_RETURN;
}
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com