ab的全称是ApacheBench,是 Apache 附带的一个小工具,专门用于 HTTP Server 的benchmark testing,可以同时模拟多个并发请求。这个小工具在apache的bin目录下面,但是每次使用都要先跳到该目录下,为了能够直接在cmd下使用,可以讲ab.exe这个文件移到C:\WINDOWS\system32路径下,这样每次使用就很方便了。
loadrunner用的好好的为什么要研究这个ab呢?我给我自己的理由是:
1.ab是开源的,很多大公司都喜欢开源的因为loadrunner太贵了,所以想成为一个性能测试高手必须要懂几个开源的性能测试工具,个人意见;
2.ab这个工具小巧使用并且很简单,上手快学习起来比较简单,而loadrunner相比起来就太复杂了,脚本开发抛开不说,就loadrunner这个工具就够学上个一个月的。
3.ab虽然很小,但是功能还是 很强大的,提供的数据足够我们使用了,其实loadrunner中虽然提供了很多功能,但是我们用能使用多少呢,性能监控这块,我 基本不用全部都是第三方监控或者linux命令,loadrunner中给出的很多指标对我们很有用的也就是1、事物的响应时间 2、事物的成功率 3、系统的吞吐量 3、在单位时间内完成的事物数这些ab基本上都可以实现。
4.如果遇到临时任务或者很简单的一个测试,可以这么说吧,开发写了一个接口让你帮他看一下性能如何,只需大概,正好你有没有loadrunner安装包,那怎么办呢,其他不说就下个loadrunner安装包估计就让开发等的不耐烦了,使用ab就不一样了很快就可以给他结果;
总而言之2者各有特点,如果做大项目,逻辑关系比较复杂的项目ab就无能为力了,所以做为一名性能测试人员就必须掌握2~3种性能测试工具,不同情况下可以使用不同的测试工具。
说了这么对废话,咱们下面就看一看这块小巧的性能测试工具吧:
我们在使用一个新工具之前当然首先看的帮助文档了,那下面我们就看看ab这个工具的帮助文档:
-n requests Number of requests to perform //在测试会话中所执行的请求个数。默认时,仅执行一个请求 -c concurrency Number of multiple requests to make //一次产生的请求个数。默认是一次一个。 -t timelimit Seconds to max. wait for responses //测试所进行的最大秒数。其内部隐含值是-n 50000。它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。 -p postfile File containing data to POST //包含了需要POST的数据的文件. -T content-type Content-type header for POSTing //POST数据所使用的Content-type头信息。 -v verbosity How much troubleshooting info to print //设置显示信息的详细程度 - 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出。 -w Print out results in HTML tables //以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。 -i Use HEAD instead of GET // 执行HEAD请求,而不是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) //-C cookie-name=value 对请求附加一个Cookie:行。 其典型形式是name=value的一个参数对。此参数可以重复。 -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. //-P proxy-auth-username:password 对一个中转代理提供BASIC认证信任。用户名和密码由一个:隔开,并以base64编码形式发送。无论服务器是否需要(即, 是否发送了401认证需求代码),此字符串都会被发送。 -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 -h Display usage information (this message) |