> /var/www/html/index.php使用ab,ph..."/>
溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

centos7 apache2.4 測(cè)試

發(fā)布時(shí)間:2020-07-02 10:30:08 來(lái)源:網(wǎng)絡(luò) 閱讀:3342 作者:titandeng 欄目:開(kāi)發(fā)技術(shù)

物理環(huán)境

VPC,64C,8G,SSD

安裝環(huán)境

centos7

apache2.4

php5.4

均使用YUM安裝。

默認(rèn)配置。

創(chuàng)建phpinfo

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

使用ab,phpinfo進(jìn)行測(cè)試

出現(xiàn)socket錯(cuò)誤繼續(xù)進(jìn)行(-r Don't exit on socket receive errors.)

使用HTTP KeepAlive功能(-k ,避免apr_pollset_poll: The timeout specified has expired (70007)錯(cuò)誤)


使用ulimit -n增加文件打開(kāi)數(shù)量

ulimit -n 65535

第一次測(cè)試

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

測(cè)試期間,新建一個(gè)會(huì)話,統(tǒng)計(jì)httpd進(jìn)程數(shù)。

ps -ef|grep httpd|wc -l
259

最多的時(shí)候是259個(gè)進(jìn)程,基本符合默認(rèn)配置最多256個(gè)httpd進(jìn)程



查看apache2.4 mpm默認(rèn)配置

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 默認(rèn)使用prefork模式,默認(rèn)設(shè)置這里沒(méi)有顯示,需在官網(wǎng)查詢

打開(kāi)查詢網(wǎng)址

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

發(fā)現(xiàn)prefork模式有以下配置

StartServers(啟動(dòng)時(shí)進(jìn)程數(shù),默認(rèn)5)
MinSpareServers(最小空閑進(jìn)程數(shù),默認(rèn)5)
MaxSpareServers(最大空閑進(jìn)程數(shù),默認(rèn)10)
MaxRequestWorkers(最大進(jìn)程數(shù),不可大于serverlimit,默認(rèn)256)
MaxConnectionsPerChild(每個(gè)進(jìn)程處理任務(wù)數(shù),達(dá)到后重啟進(jìn)程,默認(rèn)0,不重啟)
ServerLimit(程序最大進(jìn)程數(shù),默認(rèn)256)
ListenBacklog(超過(guò)MaxRequestWorkers最大服務(wù)請(qǐng)求,將連接進(jìn)行排隊(duì),默認(rèn)隊(duì)列長(zhǎng)度511)

參數(shù)調(diào)整邏輯,將以下參數(shù)

StartServers
MinSpareServers
MaxSpareServers
MaxRequestWorkers
ServerLimit

設(shè)置成同一數(shù)值,避免httpd進(jìn)程數(shù)出現(xiàn)變化,造成性能不穩(wěn)定。


不重啟進(jìn)程,節(jié)約cpu。生產(chǎn)環(huán)境需設(shè)置一個(gè)較大數(shù)值,避免內(nèi)存泄漏。

MaxConnectionsPerChild 0

將隊(duì)列調(diào)高,將來(lái)不及處理的鏈接都進(jìn)行排隊(duì)

ListenBacklog 10000


ab測(cè)試的時(shí)候加上-r -k參數(shù),避免出現(xiàn)小錯(cuò)誤時(shí)候停止測(cè)試.

-n 代表總測(cè)試次數(shù),-c 代表每秒測(cè)試次數(shù)

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

新建會(huì)話使用top(這里推薦htop)觀察內(nèi)存,cpu占用情況,如出現(xiàn)cpu或內(nèi)存超過(guò)80%負(fù)荷(在保證最高負(fù)荷時(shí)的穩(wěn)定性,一般不推薦超過(guò)80%負(fù)荷,這是個(gè)人經(jīng)驗(yàn),無(wú)測(cè)試依據(jù))情況,同步降低所有參數(shù)。


其實(shí)一般情況下默認(rèn)的參數(shù)就夠用的,如果你的設(shè)備性能非常好,才需要慢慢調(diào)整配置。

測(cè)試一次,調(diào)整一次,避免負(fù)優(yōu)化。


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI