系统centos7,apache版本2.4.6



ps aux |grep -v grep|grep httpd |wc -l

top -bn 1 |grep httpd |wc -l

都可以查看httpd并发请求进程数(正在处理的进程数)


top -bn 1 |grep httpd |awk '{print $6}'查看每个请求使用内存大小,第六列占用物理内存大小

top -bn 1 |grep httpd |awk '/httpd/{sum+=$6;n++};END{print sum/n}'

    查看平均每个请求占用的内存大小,单位是Kb

    计算最大httpd请求数,(总内存-系统500M左右)/单个请求占用内存=最大连接数


netstat -an |grep 80 |wc -l

查看与httpd服务建立的tcp连接数


httpd -l

apachectl -l    (apache2.4版本以后,这两条命令不会显示prefork模式,需用下两条命令判断)

httpd -V

都可以查看apache的运行模式(下有PS介绍apache三种运行模式,workeer,prefork,events)

httpd -M    可以查看apache加载的模块

    httpd -M |grep prefork  可以查看某个模块加载详情。



以prefork模式为例(linux默认prefork,默认最大连接数250

vim /etc/httpd/conf.modules.d/00-mpm.conf

# Select the MPM module which should be used by uncommenting exactly

# one of the following LoadModule lines:

# prefork MPM: Implements a non-threaded, pre-forking web server

# See: http://httpd.apache.org/docs/2.4/mod/prefork.html

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

# worker MPM: Multi-Processing Module implementing a hybrid

# multi-threaded multi-process web server

# See: http://httpd.apache.org/docs/2.4/mod/worker.html

#LoadModule mpm_worker_module modules/mod_mpm_worker.so

# event MPM: A variant of the worker MPM with the goal of consuming

# threads only for connections with active processing

# See: http://httpd.apache.org/docs/2.4/mod/event.html

#LoadModule mpm_event_module modules/mod_mpm_event.so

<IfModule mpm_prefork_module>

StartServers          5

MinSpareServers      10

MaxSpareServers      10

ServerLimit         610

MaxClients          600

MaxRequestsPerChild   1000

</IfModule>


参数解析:

StartServers                   5                             apache启动时候默认开始的进程数

MinSpareServers              5                             最小的闲置进程数

MaxSpareServers             10                            最大的闲置进程数

ServerLimit                      256                          最大的进程总数(参考,实际看MaxClients)

MaxClients                       256                          最大的进程总数

MaxRequestsPerChild        4000                        每个进程处理的最多请求数