解决Apache 2.2.x在Windows 2003上的内存泄露问题 -云主机博士

解决Apache 2.2.x在Windows 2003上的内存泄露问题 -云主机博士 第1张

之前,头一次在Windows Server安装这样的环境,系统运行不久后,就经常发生httpd.exe 的Memory Leak. 在网上找了很久,这个问题终于解决了,httpd.conf配置如下:

<IfModule mpm_winnt.c> 
Win32DisableAcceptEx
ThreadsPerChild 100
MaxRequestsPerChild 1000
MaxMemFree 16
ThreadLimit 100
ThreadStackSize 8192
KeepAliveTimeout 2
MaxKeepAliveRequests 10
</IfModule>

如此设置成功后,不要使用“restart", 因为使用restart的话,Apache只会停掉child thread, 再将老的parent thread复制后,生成一个新的child thread. 也就是说:你的threads设置没有生效。解决的办法是:Stop Sevice(别太心疼停服务),然后再Start Service。这样,parent tread就是一个新的进程号了,如果你不相信,可以在stop前、后,使用如下命令测试:

tasklist /FI "imagename eq httpd.exe"

当设置生效后,你就会从error.log中看到如下内容:
[Thu May 19 22:47:13 2012] [notice] Apache/2.2.4 (Win32) configured -- resuming normal operations
[Thu May 19 22:47:13 2012] [notice] Server built: Jan 9 2007 23:17:20
[Thu May 19 22:47:13 2012] [notice] Parent: Created child process 3752
[Thu May 19 22:47:13 2012] [notice] Disabled use of AcceptEx() WinSock2 API
[Thu May 19 22:47:13 2012] [notice] Child 3752: Child process is running
[Thu May 19 22:47:13 2012] [notice] Child 3752: Acquired the start mutex.
[Thu May 19 22:47:13 2012] [notice] Child 3752: Starting 100 worker threads.
[Thu May 19 22:47:13 2012] [notice] Child 3752: Listening on port 80.
[Thu May 19 22:48:00 2012] [error] [client 222.178.216.188] Invalid URI in request Connection: Keep-Alive
[Thu May 19 22:49:54 2012] [notice] Child 3752: Process exiting because it reached MaxRequestsPerChild. Signaling the parent to restart a new child process.
[Thu May 19 22:49:54 2012] [notice] Parent: Received restart signal -- Restarting the server.
[Thu May 19 22:49:54 2012] [notice] Apache/2.2.4 (Win32) configured -- resuming normal operations
[Thu May 19 22:49:54 2012] [notice] Server built: Jan 9 2007 23:17:20
[Thu May 19 22:49:54 2012] [notice] Parent: Created child process 1756
[Thu May 19 22:49:54 2012] [notice] Disabled use of AcceptEx() WinSock2 API
[Thu May 19 22:49:54 2012] [notice] Child 1756: Child process is running
[Thu May 19 22:49:55 2012] [notice] Child 3752: Released the start mutex
[Thu May 19 22:49:55 2012] [notice] Child 1756: Acquired the start mutex.
[Thu May 19 22:49:55 2012] [notice] Child 1756: Starting 100 worker threads.
[Thu May 19 22:49:55 2012] [notice] Child 3752: Waiting for 100 worker threads to exit.
[Thu May 19 22:49:55 2012] [notice] Child 1756: Listening on port 80.
[Thu May 19 22:50:03 2012] [notice] Child 3752: All worker threads have exited.
[Thu May 19 22:50:03 2012] [notice] Child 3752: Child process is exiting
注意:
当达到MaxRequestsPerChild时,apache的parent thread会启动一个新的child thread,这时你的系统中会停有3个httpd.exe进程,直到上一个进程的所有child thread都结速后,进程才会退出。
另外,上面的error log级别是:LogLevel warn

宝塔服务器面板,一键全能部署及管理,送你3188元礼包,点我领取


iproyal.png
原文链接:,转发请注明来源!
「解决Apache 2.2.x在Windows 2003上的内存泄露问题 -云主机博士」评论列表

发表评论