centos7 apache2.4 测试

物理环境php

VPC,64C,8G,SSDhtml

安装环境web

centos7apache

apache2.4centos

php5.4bash

均使用YUM安装。socket

默认配置。ide

建立phpinfo性能

echo "<?php phpinfo(); ?>" >> /var/www/html/index.php

使用ab,phpinfo进行测试
测试

出现socket错误继续进行(-r Don't exit on socket receive errors.)

使用HTTP KeepAlive功能(-k ,避免apr_pollset_poll: The timeout specified has expired (70007)错误)


使用ulimit -n增长文件打开数量

ulimit -n 65535

第一次测试

ab -r -n 20000 -c 100 'http://127.0.0.1/index.php'

测试期间,新建一个会话,统计httpd进程数。

ps -ef|grep httpd|wc -l
259

最多的时候是259个进程,基本符合默认配置最多256个httpd进程



查看apache2.4 mpm默认配置

cat /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

apache2.4 默认使用prefork模式,默认设置这里没有显示,需在官网查询

打开查询网址

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

发现prefork模式有如下配置

StartServers(启动时进程数,默认5)
MinSpareServers(最小空闲进程数,默认5)
MaxSpareServers(最大空闲进程数,默认10)
MaxRequestWorkers(最大进程数,不可大于serverlimit,默认256)
MaxConnectionsPerChild(每一个进程处理任务数,达到后重启进程,默认0,不重启)
ServerLimit(程序最大进程数,默认256)
ListenBacklog(超过MaxRequestWorkers最大服务请求,将链接进行排队,默认队列长度511)

参数调整逻辑,将如下参数

StartServers
MinSpareServers
MaxSpareServers
MaxRequestWorkers
ServerLimit

设置成同一数值,避免httpd进程数出现变化,形成性能不稳定。


不重启进程,节约cpu。生产环境需设置一个较大数值,避免内存泄漏。

MaxConnectionsPerChild 0

将队列调高,未来不及处理的连接都进行排队

ListenBacklog 10000


ab测试的时候加上-r -k参数,避免出现小错误时候中止测试.

-n 表明总测试次数,-c 表明每秒测试次数

ab -k -r -n 1000000 -c 512 'http://127.0.0.1/index.php'

新建会话使用top(这里推荐htop)观察内存,cpu占用状况,如出现cpu或内存超过80%负荷(在保证最高负荷时的稳定性,通常不推荐超过80%负荷,这是我的经验,无测试依据)状况,同步下降全部参数。


其实通常状况下默认的参数就够用的,若是你的设备性能很是好,才须要慢慢调整配置。

测试一次,调整一次,避免负优化。

相关文章
相关标签/搜索