温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

centos7 apache2.4 测试

发布时间:2020-07-02 10:30:08 来源:网络 阅读:3323 作者:titandeng 栏目:开发技术

物理环境

VPC,64C,8G,SSD

安装环境

centos7

apache2.4

php5.4

均使用YUM安装。

默认配置。

创建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%负荷,这是个人经验,无测试依据)情况,同步降低所有参数。


其实一般情况下默认的参数就够用的,如果你的设备性能非常好,才需要慢慢调整配置。

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


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI