我的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>
我意识到,这应该是暂时的解决办法,但现在的问题是,我不能发现任何泄漏,虽然任务管理器显示不变记忆力增长。
大加赞赏,