Apache2的简单性能优化.
1) MPM的选择与配置
MPM的引入是Apache 2.0最重要的变化。大家知道,Apache是基于模块化的设计,而Apache 2.0更扩展了模块化设计到Web服务器的最基本功能。服务器装载了一种多道处理模块,负责绑定本机网络端口、接受请求,并调度子进程来处理请求。
我们可以通过–with-mpm=MPM来指定MPM模块,
$./configure –help | grep mpm
结果:–with-mpm=MPM
Choose the process model for Apache to use.
MPM={beos|worker|prefork|mpmt_os2| perchild|leader|threadpool}
如果不用“–with-mpm”显式指定某种MPM,prefork就是Unix平台上缺省的MPM。它所采用的预派生子进程方式也是 Apache 1.3中采用的模式。prefork本身并没有使用到线程,2.0版使用它是为了与1.3版保持兼容性;另一方面,prefork用单独的子进程来处理不同的请求,进程之间是彼此独立的,这也使其成为最稳定的MPM之一。
make, make install完成之后, 打开httpd.conf, 修改下面
<IfModule prefork.c>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
其中的MaxClients 150改为
ServerLimit 2000
MaxClients 1000
MaxRequestsPerChild 10000
对于大多数站点已经足够了.
2) 运用mod_deflate模块来提升网页的浏览速度
关于mod_deflate的详细文档, 请参考官方文档
在configure apache2时候加入选项–enable-deflate=shared, 即可完成deflate模块的支持.
在httpd.conf里加入deflate模块的支持
LoadModule deflate_module modules/mod_deflate.so
<IfModule mod_deflate.c>
DeflateCompressionLevel 7
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/
x-httpd-php
AddOutputFilter DEFLATE js css
</IfModule>
压缩级别可以选择最大压缩率9, 不过需要占用更多的CPU.
Recent Comments