httpd 内存使用

Jam*_*tal 16 memory out-of-memory apache-httpd

httpd( Apache/2.2.29) 内存使用有一些问题。

随着时间的推移,httpd进程中的内存使用量会逐渐增加,直到最终达到 100%。

我上次重新启动httpd是在大约 24 小时前。输出free -m是:

[ec2-user@www ~]$ free -m
             total       used       free     shared    buffers     cached
Mem:          1655       1415        239          0        202        424
-/+ buffers/cache:        788        866
Swap:         1023          4       1019
Run Code Online (Sandbox Code Playgroud)

为了证明它肯定是httpd,我重新启动httpdfree -m再次运行:

[ec2-user@www ~]$ sudo service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[ec2-user@www ~]$ free -m
             total       used       free     shared    buffers     cached
Mem:          1655        760        894          0        202        360
-/+ buffers/cache:        197       1457
Swap:         1023          4       1019
Run Code Online (Sandbox Code Playgroud)

因此,重新启动 Apache 会占用从 239 Mb 到 894 Mb 的可用内存——这似乎是一个很大的飞跃。

我一直在浏览当前启用的 Apache 模块列表(有很多)和禁用/删除mod_wsgimod_perl(这两个服务器都不需要,该服务器运行基于 PHP 的 Web 应用程序 - 特别是 Magento)。

基于https://servercheck.in/blog/3-small-tweaks-make-apache-fly,我运行ps aux | grep 'httpd' | awk '{print $6/1024 " MB";}'并得到以下输出:

[root@www ~]# ps aux | grep 'httpd' | awk '{print $6/1024 " MB";}' 15.1328 MB 118.09 MB 127.449 MB 129.059 MB 117.734 MB 113.824 MB 125.062 MB 123.922 MB 119.855 MB 108.066 MB 136.23 MB 114.031 MB 113.27 MB 110.695 MB 102.113 MB 113.234 MB 186.816 MB 118.602 MB 0.835938 MB

运行其他建议的诊断工具MaxClientsps aux | grep 'httpd' | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB";}'返回以下信息:

[root@www ~]# ps aux | grep 'httpd' | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB";}'
110.212 MB
Run Code Online (Sandbox Code Playgroud)

该服务器(Amazon AWSm1.small实例)具有1.7 GbRAM。所以,因此:

关于如何最好地调整httpd设置或如何诊断究竟可能导致这种情况的任何进一步指示/建议?

Jam*_*tal 12

这是我为“解决”它所做的:

  1. 设置MaxClients 7(基于(1740.8Mb Memory on server - 900Mb for MySQL + other stuff) / 111Mb average usage per httpd process = 7.5747747747747747747747747747748

所以:

<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients         7
MaxRequestsPerChild  4000
</IfModule>
Run Code Online (Sandbox Code Playgroud)
  1. 禁用所有 Apache 模块,除了authz_host_module, log_config_module, expires_module, deflate_module, setenvif_module, mime_module, autoindex_module, negotiation_module, dir_module, alias_module, rewrite_module,php5_module

  2. 删除mod_ssl包,因为客户端没有使用https://任何东西。

一旦这个新配置运行了一段时间,我会回来报告,看看这是否能解决它。

这里的一些灵感来自:http : //www.activoinc.com/blog/2009/08/31/performance-optimized-httpd-conf-for-magento-ecommerce/http://www.activoinc.com/下载/httpd.conf-magento