文件上傳完內(nèi)存沒有得到釋放, 導(dǎo)致一致累計, 最后崩潰自動重啟
報錯時的泄漏點(位置有點飄忽不定,這附近的代碼都有概率報錯):
https://github.com/walkor/Workerman/blob/6614873e22d88f7eb761c39afcaf8301b4084283/Protocols/Http.php#L551
嘗試了手動釋放掉$_cache
并沒能解決問題
附件為strace
信息
找到一個曲線救國的方法: https://github.com/walkor/Workerman/issues/401#issuecomment-462043161
稍微優(yōu)化了一下重啟策略
Timer::add(5, function() use ($worker){
$memoryUsage = memory_get_usage(true);
if (count($worker->connections) !== 0 && $memoryUsage < $this->memoryUsageLimit[1]) {
return;
}
if ($memoryUsage > $this->memoryUsageLimit[0] || static::$requestCount > 10000) {
static::$requestCount = 0;
// Restart current process.
Worker::stopAll();
}
});
還有一點要注意: 最好是和前端溝通一下請求時在header中設(shè)置Connection: close
, 或者服務(wù)端調(diào)用close()
不保持鏈接, 增加觸發(fā)的概率