ApacheBench多URL压测改造步骤
鉴于原生ApacheBench工具默认仅具备针对单一URI执行压力测试的能力,难以契合实际业务中多样化的测试诉求,因此需要对工具进行定制化改造,从而赋予其处理多URL列表的功能。
首先需获取Apache httpd的完整源代码包,同时下载专门用于增强ab功能的patch补丁包。
wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.6.5.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.37.tar.gz
wget https://github.com/philipgloyne/apachebench-for-multi-url/archive/master.zip
需要注意的是,httpd项目的构建过程强依赖于apr与apr-util这两个基础组件库。
接下来进入编译安装阶段,优先处理apr组件。
tar -zxf apr-1.6.5.tar.gz
cd apr-1.6.5
./configure --prefix=/usr/local/apr
make && make install
随后编译并安装apr-util组件。
tar -zxf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
将下载的multi-url补丁中的ab.c文件提取出来,覆盖至httpd源码目录下的对应位置。
unzip master.zip
tar -zxf httpd-2.4.37.tar.gz
\cp ./apachebench-for-multi-url-master/ab.c ./httpd-2.4.37/support/
完成源码替换后,开始对httpd进行整体编译与安装部署。
cd httpd-2.4.37
./configure \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-mpm=prefork \
--enable-modules=most \
--enable-mpms-shared=all
make && make install
安装完成后,需对修改结果进行验证。
#/usr/local/apache/bin/ab -h
Usage: /usr/local/apache/bin/ab [options] [http[s]://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make
-t timelimit Seconds to max. wait for responses
-b windowsize Size of TCP send/receive buffer, in bytes
-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 for POSTing, 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
-x attributes String to insert as table attributes
-y attributes String to insert as tr attributes
-z attributes String to insert as td or th attributes
-C attribute Add cookie, eg. 'Apache=1234. (repeatable)
-H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
Inserted after all normal header lines. (repeatable)
-A attribute Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes
are a colon separated username and password.
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-r Don't exit on socket receive errors.
-h Display usage information (this message)
-L Use URL list file name, eg. url.txt
-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)
执行帮助命令查看输出信息,若发现倒数第三行出现了-L参数说明,即表明ab已成功集成多URL支持功能,配置工作宣告结束。
至此,关于让ApacheBench具备多URL压测能力的操作指南已介绍完毕。如需获取更多相关技术细节,建议查阅本站历史文章或持续关注后续更新,感谢大家的支持。