我也不知道我的理解對(duì)不對(duì),我的配置如下:
我有2臺(tái)服務(wù)器用來(lái)承受服務(wù)器端壓力,輪詢請(qǐng)求權(quán)重為1:1。
然后使用阿里云rds mysql數(shù)據(jù)庫(kù),數(shù)據(jù)庫(kù)采用分庫(kù)模式,一個(gè)商戶一個(gè)庫(kù),現(xiàn)在總的已達(dá)到54個(gè)商戶庫(kù),代碼是同一套在兩臺(tái)服務(wù)器上面。
webman狀態(tài)打印單臺(tái)服務(wù)器為
----------------------------------------------GLOBAL STATUS----------------------------------------------------
Workerman version:4.1.13 PHP version:7.4.33
start time:2024-07-07 13:28:49 run 15 days 11 hours
load average: 2.19, 2.39, 2.56 event-loop:\Workerman\Events\Select
3 workers 18 processes
worker_name exit_status exit_count
webman 0 2145
webman 64000 6166
webman 65280 3
webman 9 16
monitor 0 0
plugin.webman.push.server 0 0
----------------------------------------------PROCESS STATUS---------------------------------------------------
pid memory listening worker_name connections send_fail timers total_request qps status
24472 64.15M http://0.0.0.0:8787 webman 0 2 4 17011 0 [idle]
24474 69.54M http://0.0.0.0:8787 webman 0 0 4 15485 0 [idle]
24476 63.27M http://0.0.0.0:8787 webman 0 1 4 14819 0 [idle]
24478 68.2M http://0.0.0.0:8787 webman 0 0 4 15288 0 [idle]
24480 63.9M http://0.0.0.0:8787 webman 0 1 4 16659 0 [idle]
24482 81.2M http://0.0.0.0:8787 webman 1 0 4 14864 0 [idle]
24484 68.71M http://0.0.0.0:8787 webman 0 1 4 15891 0 [idle]
24485 68.21M http://0.0.0.0:8787 webman 0 1 4 15149 0 [idle]
24488 63.13M http://0.0.0.0:8787 webman 0 0 4 15916 0 [idle]
24490 67.84M http://0.0.0.0:8787 webman 0 0 4 12995 0 [idle]
24492 63.31M http://0.0.0.0:8787 webman 0 1 4 14420 0 [idle]
24494 69.39M http://0.0.0.0:8787 webman 0 2 4 15413 0 [idle]
24496 70.37M http://0.0.0.0:8787 webman 0 1 4 13976 0 [idle]
24497 62.32M http://0.0.0.0:8787 webman 0 1 4 13608 0 [idle]
24500 N/A http://0.0.0.0:8787 webman N/A N/A N/A N/A N/A [busy]
24501 69.09M http://0.0.0.0:8787 webman 0 0 4 14269 0 [idle]
26311 4.35M none monitor 0 0 3 0 0 [idle]
26312 7.28M websocket://0.0.0.0:3131 plugin.webman.push.server 180 2323 4 70963892 0 [idle]
----------------------------------------------PROCESS STATUS---------------------------------------------------
Summary 1018M - - 181 2334 67 71189655 0 [Summary]
我理解如下:
單臺(tái)服務(wù)器php進(jìn)程數(shù)為16個(gè)php進(jìn)程,那么2臺(tái)服務(wù)器為32。數(shù)據(jù)庫(kù)為54,那么連接數(shù)為54*32=1728
然后我看數(shù)據(jù)庫(kù)連接數(shù)也是這個(gè)
這么理解是不是有問(wèn)題嗎?至于說(shuō)關(guān)閉連接所有的我都試過(guò)了都不起作用
麻煩框架幫我看看怎么處理,而且大部分為了減少服務(wù)器壓力,都轉(zhuǎn)移了所有的redis以及客戶端緩存話處理了
打開(kāi) vendor/webman/think-orm/src/ThinkOrm.php ,將定時(shí)器部分注釋掉。
你要確保所有的數(shù)據(jù)庫(kù)連接被關(guān)閉。阿里云的rds有個(gè)機(jī)制,連接不關(guān)閉超過(guò)一定時(shí)間再通過(guò)這個(gè)連接訪問(wèn)會(huì)超時(shí)。
我把這個(gè)每隔55s 活躍這個(gè)注釋掉,每次創(chuàng)建會(huì)自動(dòng)回收嗎?還是必須要等待數(shù)據(jù)庫(kù)配置的超時(shí)時(shí)間自動(dòng)斷開(kāi)
下次做項(xiàng)目是不是webman的框架我最好使用框架帶的這個(gè)illuminate/database來(lái)連接?
這個(gè)大佬后期可以優(yōu)化下嗎?類似于連接池的概念webman自己封裝一個(gè),不推薦使用其他的數(shù)據(jù)庫(kù)連接,不然這玩意影響太大了。
現(xiàn)在我已經(jīng)注釋掉 并重啟了 只是在55秒等待的時(shí)候沒(méi)有重置這個(gè)活躍連接,時(shí)間一直在累加還是sleep狀態(tài),這個(gè)連接一直在,只有等數(shù)據(jù)庫(kù)配置的時(shí)間超過(guò)8小時(shí)才會(huì)自動(dòng)斷開(kāi)嗎?
注釋掉只是不讓數(shù)據(jù)庫(kù)重連。你需要在用完數(shù)據(jù)庫(kù)手動(dòng)關(guān)閉連接,比如在中間件里得到響應(yīng)后關(guān)閉數(shù)據(jù)庫(kù)連接。
php數(shù)據(jù)庫(kù)連接池解決不了你的這個(gè)問(wèn)題。
或者參考這個(gè)帖子采用use 數(shù)據(jù)庫(kù)的方式復(fù)用連接。 http://wtbis.cn/q/13019
composer require -W webman/think-orm ^1.1.2
升級(jí)下webman/think-orm,定時(shí)器里加了判斷,已經(jīng)關(guān)閉的連接不發(fā)心跳了。
好的,我現(xiàn)在試了?,F(xiàn)在連接量讓我直接起飛了 哈哈哈哈
感謝大哥
對(duì)了,這種頻繁連接會(huì)不會(huì)對(duì)性能有什么影響,感覺(jué)又走上了php-fpm,對(duì)于高并發(fā)系統(tǒng)來(lái)說(shuō)不是很友好這種解決方案。項(xiàng)目不算小,不知道大佬能不能給我點(diǎn)建議