2015-08-20 21 views
1

我的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> 

我意識到,這應該是暫時的解決辦法,但現在的問題是,我不能發現任何泄漏,雖然任務管理器顯示不變記憶力增長。

大加讚賞,

回答

1

我遇到一模一樣的你,我也檢查了我的服務器軟件與Memproof泄漏並沒有發現除了在Windows內核。我使用MaxRequestsPerChild設置爲1000000,每個子項有1500個線程。使用Apache 2.4,我不必使用powershell腳本來重置它 - Apache會自動爲您執行腳本自動執行的操作。這可能是Windows(或Apache)處理重疊連接的一個問題。不過,我猜測,我們現在使用的解決方案工作良好。也許這不會發生在Linux服務器上,但我的服務器軟件只能在Windows上運行!問候。