使用的GatewayWorker框架,
目前碰到的情況是BusinessWorker進程跑一段時間后,內(nèi)存一直在上漲,得定期重啟BusinessWorker進程,
客戶端使用WebSocket長連接,目前客戶端在2500左右,基本上7 x?24時在線(硬件),
Worker進程情況如圖1:
?
Events沒有復雜的邏輯,基本上只是在維持心跳:
class Events
{
public static function onConnect($client_id)
{
//echo $client_id . "\n";
Gateway::sendToCurrentClient(json_encode());
}
public static function onMessage($client_id, $message)
{
//file_put_contents('./debug.log', $client_id.':'.$message."\n", FILE_APPEND);
$recArrData = json_decode($message, true);
if (json_last_error() === JSON_ERROR_NONE)
{
if (isset($recArrData))
{
switch ($recArrData)
{
case 'pingBack':
return Gateway::sendToCurrentClient(json_encode());
}
}
}
}
public static function onClose($client_id)
{
self::offlineNotice('http://xxxxxxx/close/'. $client_id);
}
public static function offlineNotice($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 300);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_exec($ch);
curl_close($ch);
unset($ch);
}
}
請問是什么原因或有木有排查思路?謝謝
根據(jù)我遇到的同樣問題,個人總結的經(jīng)驗:
1、不要信百度出來的答案
2、不要懷疑是Gatewaywork的問題
3、CURL如果使用了curl_close 也不要懷疑是CURL的問題
最后拼命找了幾天,還是邏輯代碼的問題,大可能性是使用了某些函數(shù)沒釋放造成的內(nèi)存泄露。
例如相關問題解決案例:https://wenda.workerman.net/question/3732
我最終解決也是因為排查到了使用了一個create相關函數(shù)創(chuàng)建了沒釋放造成的。