ab 是 apache 对 http 服务器进行压力测试的工具,它能够测试出服务器每秒能够解决多少申请。本文记录 mac 版本 装置 ab 的步骤以及遇到的坑。
下载
进入 apache ab 官网 下载页面。
装置
brew 装置
-
因为笔者的操作系统是 mac 零碎,所以须要先装置 brew。进入 brew 网站。执行下方命令
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
执行命令后报错:
Failed to connect to raw.githubusercontent.com port 443: Connection refused
解决方案:
关上 https://www.ipaddress.com/ 查问 raw.githubusercontent.com 对应的 ip 地址。
增加 ip 到 /etc/hosts, 增加以下配置:
185.199.108.133 raw.githubusercontent.com
185.199.109.133 raw.githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.111.133 raw.githubusercontent.com
再执行
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
执行胜利后,应用 brew 装置 apr、apr-util 和 prce
brew install apr
brew install apr-util
brew inatll prce
apache ab 装置
解压下载后压缩包,进入 httpd-2.4.51 目录。
执行以下命令:
./configure
make
make install
执行 ./configure 命令时报错:
jeremy@jeremydeMacBook-Pro httpd-2.4.51 % ./configure
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-apple-darwin20.2.0
checking host system type... x86_64-apple-darwin20.2.0
checking target system type... x86_64-apple-darwin20.2.0
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found. Please read the documentation.
APR not found 没找到
./configure 改成
./configure --with-apr=/usr/local/opt/apr --with-apr-util=/usr/local/opt/apr-util --with-pcre=/usr/local/Cellar/pcre/8.45
其中 pcre 的门路可能不同,须要在 /usr/local/Cellar/pcre 外面确定门路。
上述命令执行胜利后,如果没有报错,表明装置胜利,执行 ab
ab: wrong number of arguments
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make at a time
-t timelimit Seconds to max. to spend on benchmarking
This implies -n 50000
-s timeout Seconds to max. wait for each response
Default is 30 seconds
-b windowsize Size of TCP send/receive buffer, in bytes
-B address Address to bind to when making outgoing connections
-p postfile File containing data to POST. Remember also to set -T
-u putfile File containing data to PUT. Remember also to set -T
-T content-type Content-type header to use for POST/PUT data, eg.
'application/x-www-form-urlencoded'
Default is 'text/plain'
-v verbosity How much troubleshooting info to print
-w Print out results in HTML tables
-i Use HEAD instead of GET
呈现以上界面,阐明 ab 曾经装置胜利。
运行 ab
主要参数
- -n 申请树
- -c 并发数(拜访人数)
-
-t 申请工夫最大数
ab -n 1000 -c 100 http://www.baidu.com
示意申请 baidu.com 应用 100 申请数,申请 1000 次。
总结
- 须要在配置 brew 和检测 configure 上花了比拟多的工夫。
- 其余的依照步骤即可。