优化Apache2 prefork MaxClients ServerLimit

我有一台128 GB RAM的机器,使用Apache2作为Web服务器(在这台机器上没有数据库服务器,数据库机器是64 GB的Ram机器,可以处理2000个最大连接数)。 我用一个监控工具看到,目前大约有44名忙碌的工人和12名闲散的工人,对于我的prefork模块来说,最好的理论价值是什么?

我有空白页有时在高负载小时加载网站,并得到这个错误在我的Apache错误日志:

[注意]儿童pid 13595退出信号分割故障(11)

怎么能解决这个问题呢?

我的Apache2 Prefork模块configuration:

StartServers 3 MinSpareServers 3 MaxSpareServers 5 ServerLimit 3200 MaxClients 3100 MaxRequestsPerChild 0 

在WWW上免费-h

共:128 G免费:97GB(与Apache2运行)共享0B缓冲区1.9Gcaching23G

Ram2使用Apache2和其他程序:

 Private + Shared = RAM used Program 96.0 KiB + 61.0 KiB = 157.0 KiB sh 176.0 KiB + 26.0 KiB = 202.0 KiB atd 176.0 KiB + 35.5 KiB = 211.5 KiB acpid 208.0 KiB + 19.5 KiB = 227.5 KiB mdadm 204.0 KiB + 30.0 KiB = 234.0 KiB init 248.0 KiB + 62.0 KiB = 310.0 KiB sendmail 376.0 KiB + 36.0 KiB = 412.0 KiB dbus-daemon 388.0 KiB + 285.5 KiB = 673.5 KiB cron (2) 820.0 KiB + 42.0 KiB = 862.0 KiB gam_server 920.0 KiB + 108.0 KiB = 1.0 MiB ntpd 968.0 KiB + 243.0 KiB = 1.2 MiB getty (6) 1.3 MiB + 351.5 KiB = 1.6 MiB udevd (3) 1.5 MiB + 343.0 KiB = 1.8 MiB sendmail-msp 2.0 MiB + 910.0 KiB = 2.9 MiB plugin-localresources2 3.4 MiB + 50.0 KiB = 3.4 MiB rsyslogd 3.6 MiB + 68.5 KiB = 3.7 MiB bash 1.9 MiB + 2.1 MiB = 4.0 MiB sendmail-mta (4) 3.8 MiB + 556.0 KiB = 4.3 MiB sshd (2) 3.7 MiB + 1.2 MiB = 4.8 MiB plugin-apache2 5.1 MiB + 1.2 MiB = 6.3 MiB agent-service 7.0 MiB + 654.0 KiB = 7.6 MiB fail2ban-server 9.6 MiB + 2.6 MiB = 12.2 MiB proftpd (8) 59.2 MiB + 70.0 KiB = 59.3 MiB miniserv.pl 96.8 MiB + 3.6 MiB = 100.4 MiB php5-cgi (2) 196.4 MiB + 35.9 MiB = 232.3 MiB apache2 (40) --------------------------------- tot 450.0 MiB 

Apache的prefork设置,每个Apache性能调整指南

引用:

 The single biggest hardware issue affecting webserver performance is RAM. A webserver should never ever have to swap, as swapping increases the latency of each request beyond a point that users consider "fast enough". This causes users to hit stop and reload, further increasing the load. You can, and should, control the MaxClients setting so that your server does not spawn so many children it starts swapping. This procedure for doing this is simple: determine the size of your average Apache process, by looking at your process list via a tool such as top, and divide this into your total available memory, leaving some room for other processes. 

你应该根据你的input来设置它:

  • 总内存:128 GB
  • -10%的内存除了apache:115 GB
  • 现在我们需要弄清楚有多lessapache进程正在使用。

要计算这个,你可以使用下面的脚本:

 pgrep apache2 | xargs -n1 -I{} cat /proc/{}/smaps | \ awk '{if ($0 ~ /stack/) {pids+=1} else if ($0 ~/^Shared_/) {shared+=$2} else if ($0 ~ /^Pss:/) {priv+=$2}} END { printf "%.2f MB\n",(priv+shared/(pids*pids))/1024}' 

这是对单个apache进程使用内存的最佳估计,同时尝试按照每个活动apache进程的数量按比例划分共享使用情况,并将其添加到Pss (比例集大小)

最后你用这个数字除MaxClients/ServerLimit ,你得到MaxClients/ServerLimit 。 从这里你可以相对计算其他数字

  • StartServers MaxClients的30%
  • MinSpareServers MaxClients的5%
  • MaxSpareServers MaxClients的10%
  • ServerLimit == MaxClients
  • MaxConnectionsPerChild 10000(作为解决内存泄露应用程序可能出现的问题的保守select)