码迷,mamicode.com
首页 > Web开发 > 详细

web服务器架构与Apache

时间:2015-05-04 20:23:34      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:web服务器架构与apache调优

                                   web服务器架构与Apache
 
 WEB应用系统一般由WEB服务器统一处理客户端的HTTP请求,WEB服务器负责处理静态页面,动态页面转发给应用服务器,应用服务器再将其中的数据访问请求给数据库服务器处理,
 
 客户机-->WEB服务器 --> APP服务器 —->数据库服务器
 
 MPM对Apache性能的影响
 worker MPM:使用多个子进程,每个子进程中又有多个线程,每个线程处理一个请求。该MPM通常对高流量的服务器是一个不错选择,因为它比prefork MPM需要更少的内存而且更具有伸缩性
 prefork MPM:使用多个子进程,但每个子进程并不包含多线程,每个进程只处理一个连接,在许多系统上它的速度和worker MPM一样快,但是,需要更多的内存。这种无线程的设计在某些情况下优于worker MPM,因为它可以应用于不具备线程安全的第三方模块上,且在不支持线程调试的平台上易于调试,另为还具有比worker MPM更高的稳定性
 
 调整  Max Clients
 内存是影响web服务器的重要因素之一,而且采用prefork MPM的话,由于每个进程会占据一定的内存,因此需要注意调整Max Clients参数,以便在提供足够的连接给客户端的同时,不至于耗尽服务器的内存,Max Client 是指Apache最多能启用的服务器进程数。
 如果出下一下情况,则可以推断有可能需要增加服务器内存,加到Apache的MaxClients数量
 网站在线人数增多,访问时很慢,初步认为是服务器资源不足,但反复测试,一旦连接上,不断点击同一个页面上的连接,都能迅速打开,这种现象说明Apache最大连接数已经满了,新的访客只能排队等待空闲的连接,而如果一旦连接上,KeepAlive的存活时间内都不用重新打开连接,因此解决的方法就是加大Apache的最大连接数。
 vi httpd-mpm.conf
 # 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>

# 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
# MaxRequestWorkers: maximum number of server processes allowed to start
# MaxConnectionsPerChild: maximum number of connections a server process serves
#                         before terminating
<IfModule mpm_prefork_module>
    StartServers             5 #启动Apache时就启动的服务器进程
    MinSpareServers          5 #最少保留的备用服务器进程
    MaxSpareServers         10 #最大保留的备用服务器进程
    MaxRequestWorkers      250
    MaxConnectionsPerChild   0 #一个服务器进程可处理的请求数量
</IfModule>

# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule worker.c>
ServerLimit         32
ThreadLimit         64  #必须放到最前面
StartServers         4
MaxClients         300  
MinSpareThreads     25  
MaxSpareThreads     75
ThreadsPerChild     25  
MaxRequestsPerChild  0
</IfModule>
MaxSpareServers :是指Apache最大保留的备用服务器进程,如果你的系统内存不是很充足,或者运行有其他的服务,把MaxSpareServrs设置小一些可以为其他服务空出一些内存

mod_cache
mod_cache:为了能够支持cache,需要在编译的时候启用它,默认caching是禁用的。mod_cache一共有3中mod_mem_cache,mom_disk_cache,mod_file_cache,
为了能够编译cache,需要在编译时设置
--enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache
安装后编译httpd.conf,添加
<IfModule mod_cache.c>
        CacheDefaultExpire  3600
        CacheMaxExpire    86400
        CacheLastModfiedFactor  0.1
        
    <IfModule mod_disk_cache.c>
        CacheRoot  /usr/local/apache2/cache   #创建读写权限
        CacheMaxFileSize      10000000
        CacheMinFileSize      1
        CacheEnable  disk     /               #
        CacheDirLevels        5
        CacheDirLength        3
    </IfModule>    
</IfModule>
<IfModule mod_mem_cache.c>
        CacheEnable mem      /
        MCacheSize           4096   #缓存数据最多能够使用的内存
        MCaheMaxObjectCount   2000  #内存中最多能够缓存对象的个数
        MCaheMinObjectSize    1     #单个缓存对象的最小值
        MCaheMaxObjectSize    2048  #单个缓存对象的最大值
</IfModule>

本文出自 “sar的监控命令” 博客,谢绝转载!

web服务器架构与Apache

标签:web服务器架构与apache调优

原文地址:http://rainbow9912.blog.51cto.com/9070528/1641813

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!