查找设置 MaxClients 的单个 Apache 进程的平均大小

查找设置 MaxClients 的单个 Apache 进程的平均大小

我尝试pgrep apache2在运行 Apache 的 ubuntu 10.4 上执行 pmap |grep total ,结果如下:

总计 47768K

总计 48048K

总计 48048K

总计 48048K

总计 48048K

总计 48048K

这是否意味着每个子进程占用 48 MB 的 RAM?您能帮我找出每个进程的确切内存使用情况吗?期待回复

答案1

这是我用来近似平均 httpd(如果在 Debian 发行版中则用 apache2 替代)进程大小的方法:

ps -ylC httpd --sort:rss | awk '{sum+=$8; ++n} END {print "Tot="sum"("n")";print "Avg="sum"/"n"="sum/n/1024"MB"}'

就像 symcbean 所说,您应该占用服务器内存的大约 80%,然后将其除以平均进程大小来确定上限 MaxClients。

干杯

答案2

您真的不想知道计算实际内存占用量有多么复杂。

尝试绘图

ps -ef | grep httpd | wc -l

(httpd 进程数)

针对第一个数字

free | grep 'buffers/cache'

(使用的内存量)。

适用于不同的负载水平。

请记住,缓存很重要 - 如果你的网络服务器任何I/O 则缓存越少,速度越慢。根据粗略的经验法则,您需要将 maxclients 设置为小于 80% 内存使用量的值。

答案3

我复制粘贴了你们的内容,

<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 2
MaxSpareServers 5
MaxClients 200 #must be customized
ServerLimit 200 #must be customized
MaxRequestsPerChild 100
</IfModule>

KeepAlive Off

这里有一些解释:

StartServers – this is how many apache instances should start at the very beginning when apache is started. I set it to 2, and it works fine for me.



MinSpareServers – minimum number of spare servers that should be running waiting for potential requests. MinSpareServers=2 worked fine for me too.



MaxSpareServers – maximum number of spare servers that should be running waiting for potential requests, obviously >= MinSpareServers. In my working example MaxSpareServers=5.



MaxClients & ServerLimit. You can use this shell script to determine an average amount of memory consumed by one Apache process. In addition to that it’ll show total amount of memory consumed by all Apache processes. Just unzip and execute as follows:

    wget http://cloudinservice.com/wp-content/uploads/2011/03/ap.sh.zip

    unzip ap.sh.zip

    sh ap.sh

The output will be something like that:

    Apache Memory Usage (MB): 1372.6
    Average Proccess Size (MB): 54.9041

Try to execute it several times to compare the numbers; good results will be shown when server is under a heavy load. Now when you know average amount of memory consumed by Apache and total amount of memory of your server, it is possible to calculate value to be used for MaxClients setting. For example, if in average one your Apache process consumes 50MB RAM and server RAM is 2GB, and you want to leave 512MB for the rest processes, then:
MaxClients = (2GB – 512MB)/50MB = 30.72 ~ 30.
ServerLimit is, as I understand, the same thing, but while MaxClient setting can be changed on the go without a need to restart Apache, for new ServerLimit value to take effect Apache restart is required. MaxClients should always be <= ServerLimit. To make it easy, I set ServerLimit = MaxClients calculated by above formula.

我感谢那个在她的网站上发布这篇文章的女孩。 jam

相关内容