我在服务器上遇到了一些麻烦,真的可以使用一些build议。 内存使用情况良好,系统负载情况良好。 CPU使用率非常高,显着降低了网站的速度。 它正在运行一个Drupal的定制版本。 这是一个EC2大型实例(8 GB,不确定CPU)。
这是我的Apacheconfiguration:
# # Timeout: The number of seconds before receives and sends time out. # Timeout 40 # # KeepAlive: Whether or not to allow persistent connections (more than # one request per connection). Set to "Off" to deactivate. # KeepAlive On # # MaxKeepAliveRequests: The maximum number of requests to allow # during a persistent connection. Set to 0 to allow an unlimited amount. # We recommend you leave this number high, for maximum performance. # MaxKeepAliveRequests 100 # # KeepAliveTimeout: Number of seconds to wait for the next request from the # same client on the same connection. # KeepAliveTimeout 5 # 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 # MaxClients: maximum number of server processes allowed to start # MaxRequestsPerChild: maximum number of requests a server process serves <IfModule mpm_prefork_module> StartServers 8 MinSpareServers 5 MaxSpareServers 20 MaxClients 125 MaxRequestsPerChild 400 </IfModule>
我正在使用prefork。 有任何想法吗?
CPU使用率可以从Drupal或PHP提供,不能受到Apache设置的影响。
您的第一份工作应该是查明哪些请求导致高CPU使用率。 MySQL和Apache都是笨重的CPU用户。 如果你知道原因,你可以更容易地优化它。
当然,确定原因是最好的。 不过你也可以用caching来创造奇迹。
一个简单的第一步就是实现一个操作码caching,比如APC或者Zend Optimizer +。 这将caching已编译的PHP代码,从而减less了在下一个请求中再次编译这个代码的需要。
其次,确保Drupalcaching所有可能的内容。 请参阅Drupalcaching,速度和性能 。
第三。 实现Varnish (反向代理caching)来caching所有静态内容以及实际上并不dynamic的所有dynamic内容。 如果你使用Drupal 7或Pressflow,这将是最简单的。 Varnish每秒可以处理数千个请求,CPU数量less于Apache需要服务几个,所以任何可以卸载到Varnish的请求都会减轻负载。 它已经对我们的Web服务器产生了严重的影响。 检查http://drupal.org/project/varnish提示。