【发布时间】:2015-08-20 16:05:58
【问题描述】:
我的 Apache 2.2 模块 (Windows) 似乎喜欢内存,任务管理器显示内存不断增长,直到达到 ~2GB,然后它崩溃。我根本没有使用 PHP,这不是一个网站,而是一个充当服务器的模块。多个条码扫描设备将向该服务器发送请求,该服务器将对数据库进行插入、更新、删除、查询。如果我有 10-15 台设备同时工作,我就会发现问题。
我正在使用 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>
我知道这应该是临时解决方案,但现在,问题是我无法检测到任何泄漏,尽管任务管理器显示内存不断增长。
非常感谢,
【问题讨论】:
标签: apache powershell apache2.2