Apache使用所有16​​ GB内存,如何限制其进程和内存使用量? [英] Apache using all 16 GB Memory, how to limit its processes and memory usage?

查看:52
本文介绍了Apache使用所有16​​ GB内存,如何限制其进程和内存使用量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在16GB的AWS实例上,我发现它的运行速度确实很慢.跑步

We are on 16GB AWS instance and I am finding it to be really slow. When I ran

ps -aux | grep apache

我可以看到大约60多个apache进程.

I can see about 60+ apache processes.

我跑步时

watch -n 1 "echo -n 'Apache Processes: ' && ps -C apache2 --no-headers | wc -l && free -m"

它显示了apache正在使用的几乎所有内存.

It is showing almost all memory being used by apache.

我跑步时

curl -L https://raw.githubusercontent.com/richardforth/apache2buddy/master/apache2buddy.pl | perl

要了解如何优化Apache,它建议我增加MaxRequestWorkers的数量,因此使它达到550.我还将MaxConnectionsPerChild从0(无限制)更改为10000.

to see how to optimize Apache, it suggested me to increase number of MaxRequestWorkers so I made it 550. I also changed MaxConnectionsPerChild from 0 (unlimited) to 10000.

这是我的/etc/apache2/mods-enabled/mpm_prefork.conf文件

Here is my /etc/apache2/mods-enabled/mpm_prefork.conf file

<IfModule mpm_prefork_module>
        StartServers              5
        MinSpareServers           5
        MaxSpareServers          10
        MaxRequestWorkers        550
        MaxConnectionsPerChild   10000
</IfModule>

您能告诉我如何优化apache内存使用率,以免使整个站点瘫痪吗?

Can you tell me how can we optimize apache memory usage so it don't bring down the whole site down ?

推荐答案

我在EC2中的一个实例也遇到了类似的问题,这是我所做的并且会建议:

I had a similar problem with an instance in EC2 and here's what I did and would suggest:

  1. 如果使用的是prefork,请通过键入以下两个命令来确保模块已加载 apache2 -l <​​/code>和 sudo apache2 -M 如果您可以在这两个命令之一的结果中看到预装模块已装入,则继续下一步.否则,请确保先加载它,否则将一无所获.

  1. If you are using prefork, make sure that the module is loaded by typing these two commands apache2 -l and sudo apache2 -M If you can see the prefork module loaded in the results of either of these two commands then up to the next step. Otherwise, make sure to load it first or else you would be changing the configurations for nothing.

运行此命令以查找每个apache2进程正在使用的平均内存.grep'apache2'|awk'{print $ 6/1024;}'|awk'{avg + =($ 1-avg)/NR;} END {打印avg"MB";}'将该值称为 x

Run this command to find the average memory each apache2 process is using ps aux | grep 'apache2' | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB";}' Call that value x

使用 sudo service apache2 restart 重新启动apache服务器,并记下您有多少可用内存.我所做的是从该可用内存中减去了额外的 200MB-500MB 缓冲,以供以后使用.将该值称为 y

Restart your apache server by using sudo service apache2 restart and take a note of how much free memory you have. What I did was subtract an extra 200MB-500MB cushion from that free memory to be used later. Call that value y

将可用内存 y 的值除以每个进程 x 所使用的内存量,这将是 MaxRequestWorkers = y/x

Divide the value of free memory y over the amount of memory used per process x and that would be the value of MaxRequestWorkers = y/x

对于 MaxConnectionsPerChild 的值,您可以对其进行调整,直到获得正确的配置.如果将其设置得太大,则该进程将在被杀死之前继续使用越来越多的内存.如果将其设置得太小,则进程将死得太快,这将给系统带来开销.我通常将其保留在 4000 10000 之间.

As for the value of MaxConnectionsPerChild then you can tweak it till you get the right configuration. It you make it too big, then the process will keep using more and more memory before being killed. If you make it too small, then the processes will die too quickly and that will present an overhead on your system. I usually keep it somewhere between 4000 and 10000.

其中一些步骤是从以下链接中的可接受答案中采取的: StackExchange:httpd内存使用情况,其中一种解决方案还建议您禁用一些不需要的模块.

Some of these steps have been taken from the accepted answer in the following link: StackExchange: httpd memory usage where one solution also suggested disabling some of the modules if you don't need them.

我建议您先执行第1-5步,看看是否能解决您的问题!

I would suggest you do steps 1-5 first and see if that solves your problem!

祝你好运!

这篇关于Apache使用所有16​​ GB内存,如何限制其进程和内存使用量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆