我正在运行一个网站,在特定的时间得到大量使用。 我在EC2 Ubuntu 16.04服务器上运行apache 2.4,使用4核CPU和16GB内存和2GB交换。 平均apache进程的大小是35MB(大约)。 我将KeepAlive值设置为ON,并将KeepAliveTimeout设置为5的较低值。
我正在使用MPM prefork,configuration如下所示:
<IfModule mpm_prefork_module> StartServers 5 MinSpareServers 5 MaxSpareServers 10 ServerLimit 350 MaxRequestWorkers 350 MaxConnectionsPerChild 20000 </IfModule>
当并发用户数量增加时,htop显示所有4个内核都被100%利用,但是在可用的15GB中RAM仍然只显示1.5或2GB。
为什么没有使用更多的内存? 有这种CPU使用情况是正常的吗? 如果用户数从这里增加,则服务器开始返回HTTP 522错误。
附加信息:用于获取值的计算参考本教程和ServerFault上的这个答案
我发现一个单一的Apache进程占用大约35MB的内存。 我在PM2下运行nodejs(for socketio)。 MySQL从RDS运行,不在此服务器上。 尽pipe如此,根据build议的计算,我已经减less了一些值:
Available Memory - 14000MB
(将其余的RAM留作其他用途)
Apache Process usage - 40MB MaxRequestWorkers = 14000/40 = 350 StartServers 30% of MaxRequestWorkers
(应该是105,但是我觉得太高了,应该把它做成105?)
MinSpareServers 5% of MaxRequestWorkers
(应该是17)
MaxSpareServers 10% of MaxClients
(这个值是否和StartServers一样高达105?
ServerLimit = MaxRequestWorkers
编辑我修改了preforkconfiguration,使用build议的计算:
<IfModule mpm_prefork_module> StartServers 105 MinSpareServers 17 MaxSpareServers 105 ServerLimit 350 MaxRequestWorkers 350 MaxConnectionsPerChild 20000 </IfModule>
我运行了一个脚本,可以进行2个API调用,模仿一个用户login并执行一些操作4次。 同时运行这些脚本中的20个,使用新的configuration仍然给出了高负载平均值: