我的Apache 2.2模塊(Windows)似乎喜歡內存,任務管理器顯示內存不斷增長,直到達到2GB,然後崩潰。我根本不使用PHP,這不是一個網站,而是一個充當服務器的模塊。許多條形碼掃描設備將向該服務器發送請求,並且該服務器將對數據庫執行插入,更新,刪除和查詢。我看到這個問題,如果我有10-15設備在同一時間工作。Apache內存泄漏 - 無PHP使用
我正在使用FastMM來檢測我的Apache模塊中的內存泄漏,FastMM沒有報告任何泄漏。如果我故意介紹一個,我可以看到FastMM發生泄漏。
這告訴我,Apache不釋放內存到操作系統,這隻在某些情況下發生。如果我只有1-2個設備,那麼這個問題不會發生。所以,我的猜測是,這是由於發送給Apache的大量請求導致的。
作爲臨時解決方案,我使用PowerShell(版本2.0或4.0,取決於計算機)腳本在達到內存閾值時重新啓動Apache。我的PowerShell腳本這樣做是爲了阻止apache進程和服務,並啓動它(如果內存已達到CA 0.8GB),而這一切的作品,我測試了它:
# If working set of httpd or httpd#1 is greater than threshold, stop and start
if($procobj.workingset -gt $Threshold)
{
# $ProcName is name of process reported by PowerShell (as httpd, httpd#1, httpd#2, ...)
echo $("Memory for " + $ProcName + " exceeds Threshold");
# Stop httpd process
stop-process -name $MyHTTPD -force
# Stop service $ServiceName (this is name of service in Windows->Services)
echo $("---> Stopping service: " + $ServiceName);
stop-Service $ServiceName;
# Start service $ServiceName (this is name of service in Windows->Services)
echo $("---> Starting service: " + $ServiceName);
start-Service $ServiceName;
}
正如你所看到的,我來控制的httpd進程,然後停止Apache服務,然後啓動將產生新的httpd進程的服務。
而且,這裏是Apache的設置,我使用:
#Commented out these 3 in httpd.conf
#KeepAlive On
#MaxKeepAliveRequests 0
#KeepAliveTimeout 3000
#these are in mod_mpm
# WinNT MPM
<IfModule mpm_winnt_module>
ThreadsPerChild 300
#MaxRequestsPerChild 0
MaxRequestsPerChild 50
#According to Apache documentation, if you get "An operation was
#attempted on something that is not a socket), you should use this to
#disable AcceptEx() WinSock v2 API. See:
# http://httpd.apache.org/docs/2.2/mod/mpm_winnt.html
Win32DisableAcceptEx
</IfModule>
我意識到,這應該是暫時的解決辦法,但現在的問題是,我不能發現任何泄漏,雖然任務管理器顯示不變記憶力增長。
大加讚賞,