简介

ab(Apache Bench)是Apache附带的压力测试软件,容易使用,功能完全能够满足我们的要求,安装apache时会自带该压力测试软件

参数说明

ab自带的参数说明:

[root@xiaozhu images]# ab -h
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
    -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)
    -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)

ab的参数比较多,常用的就几个:

  • -n :在测试会话中执行的请求个数,即请求数,默认执行一个请求
  • -c :要创建的并发用户数,即并发数,默认创建一个用户数
  • -t :等待Web服务器响应的最大时间(单位:秒),默认没有时间限制
  • -k :使用Keep-Alive(持久连接)特性
  • -C :对请求附加一个Cookie,形式为 name=value

用法

下面使用ab进行一次压力测试:

[root@xiaozhu images]# ab -c5 -n100 -k xxx.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking cms.dev.paidui.com (be patient).....doneServer Software: Tengine
Server Hostname: cms.dev.paidui.com
Server Port: 80Document Path: /
Document Length: 30692 bytesConcurrency Level: 5
Time taken for tests: 20.663 seconds
Complete requests: 100
Failed requests: 10(Connect: 0, Receive: 0, Length: 10, Exceptions: 0)
Write errors: 0
Non-2xx responses: 10
Keep-Alive requests: 10
Total transferred: 2881762 bytes
HTML transferred: 2822279 bytes
Requests per second: 4.84 [#/sec] (mean)
Time per request: 1033.169 [ms] (mean)
Time per request: 206.634 [ms] (mean, across all concurrent requests)
Transfer rate: 136.19 [Kbytes/sec] receivedConnection Times (ms)min mean[+/-sd] median max
Connect: 0 5 2.1 6 11
Processing: 9 984 1007.0 739 7508
Waiting: 9 330 230.7 257 1278
Total: 9 989 1007.2 744 7513Percentage of the requests served within a certain time (ms)50% 74466% 91975% 113080% 122290% 177295% 242298% 472099% 7513100% 7513 (longest request)

测试结果一目了然,吞吐率为4.84 reqs/s(吞吐率即单位时间内服务器处理的请求数)

测试结果中关注以下内容:

  • Server Software: 被测试Web服务器的软件名称
  • Server Hostname: 请求URL中的主机名称
  • Server Port: 被测试Web服务器的侦听端口
  • Document Path: 请求的URL的绝对路径
  • Document Length: HTTP响应数据的正文长度
  • Concurrency Level: 并发用户数,设置的“-c”参数
  • Time taken for tests: 所有请求处理完成所花费的总时间
  • Complete requests: 总请求数,设置的“-n”参数
  • Failed requests: 失败的请求数
  • Total transferred: 所有请求的响应数据长度总和
  • HTML transferred: 所有请求的响应数据中正文数据的总和,也就是减去Total transferred中HTTP响应数据中头信息的长度
  • Requests per second: Web服务器的吞吐率,等于 Complete requests/Time taken for tests
  • Time per request: 用户平均请求等待时间,等于 Time taken for tests/(Complete requests/Concurrency Level)
  • Transfer rate: 这些请求在单位时间内从服务器取得的数据长度,等于 Total transferred/Time taken for tests

持久连接

持久连接(Keep-Alive)又称长连接,指TCP连接中连续发送多份数据而不断开的连接,与之对应的称为短连接,就是连接后发送一次数据便断开的连接。长连接对于密集型图片或者网页等小数据请求处理有明显的加速作用。

在请求大量小文件时,长连接能够有效地减少重新建立连接的开销。在启动ab时加上-k参数可以使用Keep-Alive模式进行测试

比如:

先测试不使用长连接请求一个图片:

[root@xiaozhu images]# ab -c10 -n1000 cms.dev.paidui.com/images/3gphost.jpg
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking cms.dev.paidui.com (be patient)Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requestsServer Software: Tengine
Server Hostname: cms.dev.paidui.com
Server Port: 80Document Path: /images/3gphost.jpg
Document Length: 169 bytesConcurrency Level: 10
Time taken for tests: 5.166 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Non-2xx responses: 1000
Total transferred: 659912 bytes
HTML transferred: 169000 bytes
Requests per second: 193.59 [#/sec] (mean)
Time per request: 51.657 [ms] (mean)
Time per request: 5.166 [ms] (mean, across all concurrent requests)
Transfer rate: 124.76 [Kbytes/sec] receivedConnection Times (ms)min mean[+/-sd] median max
Connect: 4 5 1.2 5 17
Processing: 14 46 26.9 39 219
Waiting: 14 46 26.9 39 219
Total: 19 51 26.9 44 224Percentage of the requests served within a certain time (ms)50% 4466% 4975% 5280% 5590% 6495% 11398% 17499% 193100% 224 (longest request)

不使用长连接的时候吞吐率为193.59

下面使用长连接:

[root@xiaozhu images]# ab -c10 -n1000 -k cms.dev.paidui.com/images/3gphost.jpg
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking cms.dev.paidui.com (be patient)Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requestsServer Software: Tengine
Server Hostname: cms.dev.paidui.com
Server Port: 80Document Path: /images/3gphost.jpg
Document Length: 169 bytesConcurrency Level: 10
Time taken for tests: 3.086 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Non-2xx responses: 1000
Keep-Alive requests: 992
Total transferred: 648975 bytes
HTML transferred: 169000 bytes
Requests per second: 324.08 [#/sec] (mean)
Time per request: 30.856 [ms] (mean)
Time per request: 3.086 [ms] (mean, across all concurrent requests)
Transfer rate: 205.39 [Kbytes/sec] receivedConnection Times (ms)min mean[+/-sd] median max
Connect: 0 0 0.8 0 7
Processing: 12 31 21.7 27 232
Waiting: 12 31 21.7 27 232
Total: 12 31 22.2 27 238Percentage of the requests served within a certain time (ms)50% 2766% 3175% 3480% 3590% 4095% 4698% 5399% 220100% 238 (longest request)

使用长连接的吞吐率为324,除此之外,Keep-Alive request为992,即使用长连接的有992个请求,也就是说有992个请求重用同一个TCP连接。

参考资料

《PHP核心技术与最佳实践》的第11章 高性能网站架构方案

【压测】压力测试ab的用法【原创】.md相关推荐

  1. 压测工具之ab(ApacheBench)安装及使用

    ab是apache自带的压力测试工具.ab不仅可以对apache服务器进行网站访问压力测试,也可以对或其它类型的服务器进行压力测试. 使用如下命令安装: yum install httpd-tools ...

  2. 压力测试ab安装 linux,Centos8下安装ab压力测试工具及ab命令详解

    释放双眼,带上耳机,听听看~! 1.ab的简介 ab是apachebench命令的缩写. ab是apache自带的压力测试工具.ab非常实用,它不仅可以对apache服务器进行网站访问压力测试,也可以 ...

  3. php压力测试ab.exe,apache ab工具页面压力测试返回结果含义解释

    ab是apache自带的一个很好用的压力测试工具,当安装完apache的时候,就可以在bin下面找到ab 参数说明及示例 我们可以模拟100个并发用户,对一个页面发送1000个请求 其中-n代表请求数 ...

  4. Web性能压力测试工具webbench用法

    测试环境:Centos7 一.安装webbench 1.安装依赖 #yum -y install gcc automake autoconf libtool make ctags 2.安装ctags及 ...

  5. httpd二之主配置文件详解、测试工具、压力测试ab

    本文主要讲述httpd的主配置文件中可以配置的选项以及参数,以2.2系列的为主,在http2.4以后会添加一些新的功能和模块,配置文件可能也会有一些差别,关于2.4的配置文件将在后续推出,敬请期待! ...

  6. 压测瓶颈在mysql_MySQL的性能基线收集及压力测试

    建立基线的作用: 计算机科学中,基线是项目储存库中每个工件版本在特定时期的一个"快照". 比如我们现在有并发事物,那么在某时刻发起一个事物会产生当前数据的快照,那么这个快照就相当理 ...

  7. ab压力测试代码及实现过程

    进行压力测试;书写代码如下: 首先进入apache中的bin目录 我安装的是wamp环境,  输入ab, 出现如下图 进行压力测试; ab 的用法是:ab [options] [http://]hos ...

  8. php mysql 压力测试_MySQL的性能基线收集及压力测试

    建立基线的作用: 计算机科学中,基线是项目储存库中每个工件版本在特定时期的一个"快照". 比如我们现在有并发事物,那么在某时刻发起一个事物会产生当前数据的快照,那么这个快照就相当理 ...

  9. 数据库MySQL的性能基线收集及压力测试

    建立基线的作用: 计算机科学中,基线是项目储存库中每个工件版本在特定时期的一个"快照". 比如我们现在有并发事物,那么在某时刻发起一个事物会产生当前数据的快照,那么这个快照就相当理 ...

最新文章

  1. DNS,edns,httpdns杂谈
  2. python比前端好学吗_前端学习到底难不难?
  3. windows ffmpeg 的安装
  4. Hadoop配置机架感知(python脚本)
  5. 甲骨文是否可以要求 Java API 享有版权?这场10年官司怎么结
  6. Console-算法[for]-国王与老人的六十四格
  7. SpringBoot-(1)-IDEA创建SpringBoot项目并运行访问接口
  8. anaconda安装numpy_Windows安装cpu版pytorch和tensorflow
  9. 数据结构笔记(十九)-- 二叉树性质
  10. SQL Server2008表及字段描述信息处理示例
  11. X265源码下载地址
  12. 如何让普通用户执行一些root用户才能执行的命令
  13. NSTimer(2)
  14. 小暑海报文案|小暑海报设计图片素材
  15. SaaS产品移动化,你想好这3点了吗
  16. 应用商店安装ubantu_从 Play 商店下载 Android 应用安装文件 .apk
  17. k8s+containerd+kata-containers 安装
  18. iphone5信号无服务器,iPhone手机信号这么强,原因是开启了“它”,果粉:有救了...
  19. Arduino基础入门篇02—Arduino开发环境IDE安装使用
  20. 数据挖掘之时间序列模型(最全流程分析)

热门文章

  1. 黑马程序员视频教程学习mybatis框架常用注释SQL语句学习笔记?
  2. usleep()和sleep()的区别
  3. 果园大二下英方课学习姿势
  4. 说一说递归里的return返回!!!
  5. android源码下载(上)
  6. 数据结构笔记(持续更新)
  7. ZEMAX像质评价及六种像差汇总
  8. 遥感影像的几何校正介绍
  9. Element DatePicker 日期选择器禁用单个指定日期
  10. c语言与java的区别