Apache内存泄漏 - 没有使用PHP

时间:2015-08-20 16:05:59

标签: apache powershell apache2.2

我的Apache 2.2模块(Windows)似乎喜欢内存,任务管理器显示内存不断增长,直到达到~2GB,然后崩溃。我根本不使用PHP,这不是一个网站,而是一个充当服务器的模块。许多条形码扫描设备将向此服务器发送请求,此服务器将对数据库执行插入,更新,删除和查询。如果我有10-15台设备同时工作,我就会看到这个问题。

我使用FastMM来检测Apache模块中的内存泄漏,而FastMM没有报告任何泄漏。如果我故意介绍一个,我可以看到FastMM发生泄漏。

这告诉我Apache没有向操作系统释放内存,这只在某些情况下发生。如果我只有1-2个设备,那么这个问题就不会发生了。所以,我的猜测是它是由发送给Apache的大量请求引起的。

作为临时解决方案,我使用PowerShell(版本2.0或4.0,取决于计算机)脚本在达到内存阈值时重新启动Apache。我的PowerShell脚本正在执行此操作以停止apache进程和服务并启动它(如果内存已达到大约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 个答案:

答案 0 :(得分:1)

我遇到的情况和你完全一样,我也检查了我的服务器软件是否有Memproof泄漏,除了在Windows内核中没有发现任何东西。我使用MaxRequestsPerChild设置为1000000,每个孩子有1500个线程。使用Apache 2.4,我不必使用powershell脚本来重置它 - Apache会自动执行脚本为我做的事情。这可能是Windows(或Apache)处理重叠连接的方式的问题。但是,我猜测,我们现在使用的解决方案工作正常。也许这不会发生在Linux服务器安排上,但我的服务器软件只能在Windows上运行!问候。

相关问题