日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線(xiàn)溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
MySQL數(shù)據(jù)庫(kù)線(xiàn)程緩沖池詳解

MySQL數(shù)據(jù)庫(kù)線(xiàn)程緩沖池的相關(guān)知識(shí)是本文我們主要要介紹的內(nèi)容,MySQL數(shù)據(jù)庫(kù)支持線(xiàn)程緩存,在多線(xiàn)程連接模式下,如果連接斷開(kāi)后,將這個(gè)線(xiàn)程放入空閑線(xiàn)程緩沖區(qū),在下次有連接到來(lái)時(shí),先去緩沖池中查找是否有空閑線(xiàn)程,有則用之,無(wú)則創(chuàng)建。啟動(dòng)時(shí)可以設(shè)置線(xiàn)程緩沖池的數(shù)目:Mysqld.exe --thread_cache_size=10。

創(chuàng)新互聯(lián)公司專(zhuān)注為客戶(hù)提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都做網(wǎng)站、網(wǎng)站制作、興慶網(wǎng)絡(luò)推廣、成都微信小程序、興慶網(wǎng)絡(luò)營(yíng)銷(xiāo)、興慶企業(yè)策劃、興慶品牌公關(guān)、搜索引擎seo、人物專(zhuān)訪(fǎng)、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供興慶建站搭建服務(wù),24小時(shí)服務(wù)熱線(xiàn):18982081108,官方網(wǎng)址:www.cdcxhl.com

在一個(gè)連接斷開(kāi)時(shí),會(huì)調(diào)用cache_thread函數(shù),將空閑的線(xiàn)程加入到cache中,以備后用。源碼如下:

 
 
 
  1. static bool cache_thread()  
  2. {  
  3. safe_mutex_assert_owner(&LOCK_thread_count);  
  4. if (  
  5. cached_thread_count < thread_cache_size 
  6. &&  
  7. ! abort_loop && !kill_cached_threads)  
  8. {  
  9. /* Don't kill the thread, just put it in cache for reuse */  
  10. DBUG_PRINT("info", ("Adding thread to cache"));  
  11. cached_thread_count++;  
  12. while (!abort_loop && ! wake_thread && ! kill_cached_threads)  
  13. (void) pthread_cond_wait(&COND_thread_cache, &LOCK_thread_count);  
  14. cached_thread_count--;  
  15. if (kill_cached_threads)  
  16. pthread_cond_signal(&COND_flush_thread_cache);  
  17. if (wake_thread)  
  18. {  
  19. THD *thd;  
  20. wake_thread--;  
  21. thd= thread_cache.get();  
  22. thd->thread_stack= (char*) &thd;          // For store_globals  
  23. (void) thd->store_globals();  
  24. /*  
  25. THD::mysys_var::abort is associated with physical thread rather  
  26. than with THD object. So we need to reset this flag before using  
  27. this thread for handling of new THD object/connection.  
  28. */  
  29. thd->mysys_var->abort= 0;  
  30. thd->thr_create_utime= my_micro_time();  
  31. threads.append(thd);  
  32. return(1);  
  33. }  
  34. }  
  35. return(0);  

上面我們的啟動(dòng)參數(shù)設(shè)置線(xiàn)程緩沖區(qū)為10,此時(shí)對(duì)應(yīng)代碼里面的thread_cache_size = 10,cached_thread_count記錄

了此刻cache中的空閑線(xiàn)程數(shù)目,只有在cache未滿(mǎn)的情況下,才會(huì)將新的空閑線(xiàn)程加入緩沖池中。加入到緩沖區(qū)其實(shí)就是將線(xiàn)

程掛起,pthread_cond_wait函數(shù)便是線(xiàn)程等待函數(shù),在此函數(shù)中,會(huì)調(diào)用WaitForMultipleObjects進(jìn)行事件等待。具體源碼

如下:

 
 
 
  1. int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,  
  2. struct timespec *abstime)  
  3. int result;  
  4. long timeout;   
  5. union ft64 now;  
  6. if( abstime != NULL )  
  7. {  
  8. GetSystemTimeAsFileTime(&now.ft);  
  9. /*  
  10. Calculate time left to abstime  
  11. - subtract start time from current time(values are in 100ns units)  
  12. - convert to millisec by dividing with 10000  
  13. */  
  14. timeout= (long)((abstime->tv.i64 - now.i64) / 10000);  
  15. /* Don't allow the timeout to be negative */  
  16. if (timeout < 0)  
  17. timeout= 0L;  
  18. /*  
  19. Make sure the calucated timeout does not exceed original timeout  
  20. value which could cause "wait for ever" if system time changes  
  21. */  
  22. if (timeout > abstime->max_timeout_msec)  
  23. timeout= abstime->max_timeout_msec;  
  24. }  
  25. else  
  26. {  
  27. /* No time specified; don't expire */  
  28. timeout= INFINITE;  
  29. }  
  30. /*   
  31. Block access if previous broadcast hasn't finished.  
  32. This is just for safety and should normally not  
  33. affect the total time spent in this function.  
  34. */  
  35. WaitForSingleObject(cond->broadcast_block_event, INFINITE);  
  36. EnterCriticalSection(&cond->lock_waiting);  
  37. cond->waiting++;  
  38. LeaveCriticalSection(&cond->lock_waiting);  
  39. LeaveCriticalSection(mutex);  
  40. result= WaitForMultipleObjects(2, cond->events, FALSE, timeout);  
  41. EnterCriticalSection(&cond->lock_waiting);  
  42. cond->waiting--;  
  43. if (cond->waiting == 0)  
  44. {  
  45. /*  
  46. We're the last waiter to be notified or to stop waiting, so  
  47. reset the manual event.   
  48. */  
  49. /* Close broadcast gate */  
  50. ResetEvent(cond->events[BROADCAST]);  
  51. /* Open block gate */  
  52. SetEvent(cond->broadcast_block_event);  
  53. }  
  54. LeaveCriticalSection(&cond->lock_waiting);  
  55. EnterCriticalSection(mutex);  
  56. return result == WAIT_TIMEOUT ? ETIMEDOUT : 0;  

此處是等待時(shí)間,何處進(jìn)行事件通知呢?我們?cè)俅蝸?lái)到上篇所提及的為新的連接創(chuàng)建線(xiàn)程的代碼中:

 
 
 
  1. void create_thread_to_handle_connection(THD *thd)  
  2. {  
  3. if (cached_thread_count > wake_thread)  
  4. {  
  5. /* Get thread from cache */  
  6. thread_cache.append(thd);  
  7. wake_thread++;  
  8. pthread_cond_signal(&COND_thread_cache);  
  9. }  
  10. Else  
  11. ...  

關(guān)于MySQL數(shù)據(jù)庫(kù)線(xiàn)程緩沖池的相關(guān)知識(shí)就介紹到這里了,希望本次的介紹能夠?qū)δ兴斋@!

【編輯推薦】

  1. 如何檢查MySQL數(shù)據(jù)庫(kù)的主從延時(shí)?
  2. MySQL數(shù)據(jù)庫(kù)時(shí)間類(lèi)型的物理存儲(chǔ)
  3. Linux cron執(zhí)行MySQL失敗的問(wèn)題解決方案
  4. PHP與MySQL數(shù)據(jù)庫(kù)中排序的對(duì)比及使用條件詳解
  5. MySQL性能優(yōu)化之使用Limit關(guān)鍵字來(lái)避免全表掃描

網(wǎng)站欄目:MySQL數(shù)據(jù)庫(kù)線(xiàn)程緩沖池詳解
標(biāo)題網(wǎng)址:http://www.5511xx.com/article/dhjhsdo.html