阿帕奇崩溃VPS – 需要减less内存使用量

我有一个运行使用Apache服务的Web应用程序的VPS,平均每秒处理20-50个请求。 通常高于这一点(每秒50个请求),Apache使用的内存量对于VPS来说太高,并且错误开始发生 – 网页崩溃,VPS在回到正常水平之前摔倒一两分钟。

我相信MaxClients是减lessApache使用的RAM的最好方法,我计划将MaxClients从256(默认值)减less到100左右。每个Apache进程使用〜15MB,服务器总共有1900MB的RAM – 服务器除了运行Apache和几个cron之外别无其他。

当前设置是:

KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 3 # prefork MPM # StartServers: number of server processes to start # MinSpareServers: minimum number of server processes which are kept spare # MaxSpareServers: maximum number of server processes which are kept spare # ServerLimit: maximum value for MaxClients for the lifetime of the server # MaxClients: maximum number of server processes allowed to start # MaxRequestsPerChild: maximum number of requests a server process serves <IfModule prefork.c> StartServers 8 MinSpareServers 5 MaxSpareServers 20 ServerLimit 256 MaxClients 256 MaxRequestsPerChild 4000 </IfModule> 

我试图减lessMaxClients之前,导致巨大的缓慢,所以我需要一些其他的select。

我的build议是把MaxClients减less到100吗? 如果服务器再次遇到缓慢,我有什么select – 优化应用程序? 减less内存使用量的最佳方法是什么 – 将图像移动到另一个Web服务器?

任何build议感激地收到!

减lessapache的内存使用的最好方法是远离mod_php和类似fastcgi的东西。 由于mod_php开销(很有可能),你的每个apache进程都是15mb或更多。 有了PHP的请求交给fastcgi将取决于Apacheconfiguration将平均apache进程大小减less到大约1mb左右。

由于php现在使用fastcgi进行集中,所以内存使用效率更高,系统使用的内存总量应该稍微减less。

另一种方法是在apache之前放置一个更高效的http服务器,并直接向服务器提供静态内容,并向apache代理非静态请求。 Nginx会很棒。

作为一个临时的解决scheme,你也可以考虑将MaxRequestsPerChild减less到1000或更积极的东西。 由于apache进程在服务请求的时候往往会增长,所以会通过closures它们并产生新的进程来限制它们的大小。