[[email protected] ~]# ab -c 100 -n 1000 http://192.168.1.21/
//100個用戶端,通路了1000次
[[email protected] ~]# ab -c 1000 -n 10000 http://192.168.1.21/
Concurrency Level: 1000 //一千個客戶
Time taken for tests: 26.645 seconds //處理的時間
Complete requests: 10000 //通路的次數
Failed requests: 81 //失敗的次數
檢視浏覽器:
http://192.168.1.21/httpd-status
148 requests currently being processed, 0 idle workers //目前的通路量
[[email protected] ~]# ab -c 5000 -n 50000 http://192.168.1.21/
This is ApacheBench, Version 2.3 < Revision:1430300 R e v i s i o n : 1430300 >
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.1.21 (be patient)
socket: Too many open files (24) //打開的檔案太多。是系統的原因
[[email protected] ~]# ulimit -SHn 65535 //把系統的通路量調大點
[[email protected] ~]# ab -c 5000 -n 50000 http://192.168.1.21/ //執行到一半就會失敗
檢視一下記憶體和cpu
uptime free -m
解決方法:
修改apache的線程:
[[email protected] ~]# cd /etc/httpd/conf.modules.d/
[[email protected] conf.modules.d]# vim 00-mpm.conf
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
MaxClients 1024
[[email protected] conf.modules.d]# apachectl -t //文法檢測
AH00180: WARNING: MaxRequestWorkers of 1024 exceeds ServerLimit value of
256 servers, decreasing MaxRequestWorkers to 256.
To increase, please see the ServerLimit directive.
Syntax OK
[[email protected] conf.modules.d]# vim 00-mpm.conf
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
MaxClients 1024
ServerLimit 1024
[[email protected] conf.modules.d]# apachectl -t
Syntax OK
[[email protected] conf.modules.d]# apachectl graceful //重起服務
[[email protected] conf.modules.d]# pstree -p
[[email protected] httpd]# grep -Ri keepalive . //了解