在学习ab工具之前,我们需了解几个关于压力测试的概念

  1. 吞吐率(Requests per second)
    概念:服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。
    计算公式:总请求数 / 处理完成这些请求数所花费的时间,即
    Request per second = Complete requests / Time taken for tests

  2. 并发连接数(The number of concurrent connections)
    概念:某个时刻服务器所接受的请求数目,简单的讲,就是一个会话。

  3. 并发用户数(The number of concurrent users,Concurrency Level)
    概念:要注意区分这个概念和并发连接数之间的区别,一个用户可能同时会产生多个会话,也即连接数。

  4. 用户平均请求等待时间(Time per request)
    计算公式:处理完成所有请求数所花费的时间/ (总请求数 / 并发用户数),即
    Time per request = Time taken for tests /( Complete requests / Concurrency Level)

  5. 服务器平均请求等待时间(Time per request: across all concurrent requests)
    计算公式:处理完成所有请求数所花费的时间 / 总请求数,即
    Time taken for / testsComplete requests
    可以看到,它是吞吐率的倒数。
    同时,它也=用户平均请求等待时间/并发用户数,即
    Time per request / Concurrency Level

ab工具简介

ab是apache自带的压力测试工具。ab非常实用,它不仅可以对apache服务器进行网站访问压力测试,也可以对或其它类型的服务器进行压力测试。比如nginx、tomcat、IIS等。

安装:

ycz@ubuntu:~$ ab
程序“ab”尚未安装。 您可以使用以下命令安装:
sudo apt-get install apache2-utils
ycz@ubuntu:~$ sudo apt-get install apache2-utils

参数列表:

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
-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.
-q Do not show progress when doing more than 150 requests
-l Accept variable document length (use this for dynamic pages)
-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
(SSL3, TLS1, TLS1.1, TLS1.2 or ALL)

开始测试


输入命令

ycz@ubuntu:~$ ab -n 100 -c 10 http://sewise.21321.com/redistest/RedisSaveToMysqlJson

其中-n表示请求数,-c表示并发数

请求测试代码:$redisInfo 是一个Json数组

  • 这段展示的是web服务器的信息,可以看到服务器采用的是nginx,域名是wan.bigertech.com,端口是80

   

  • 这段是关于请求的文档的相关信息,所在位置“/”,文档的大小为338436 bytes(此为http响应的正文长度)  

    

  • 这段展示了压力测试的几个重要指标

   

 Concurrency Level: 100    //并发请求数
Time taken for tests: 50.872 seconds //整个测试持续的时间
Complete requests: 1000 //完成的请求数
Failed requests: 0 //失败的请求数 Total transferred: 13701482 bytes //整个场景中的网络传输量
HTML transferred: 13197000 bytes //整个场景中的HTML内容传输量

Requests per second: 19.66 [#/sec] (mean) //吞吐率,大家最关心的指标之一,相当于 LR 中的每秒事务数,后面括号中的 mean 表示这是一个平均值

Time per request: 5087.180 [ms] (mean) //用户平均请求等待时间,大家最关心的指标之二,相当于 LR 中的平均事务响应时间,后面括号中的 mean 表示这是一个平均值

Time per request: 50.872 [ms] (mean, across all concurrent requests) //服务器平均请求处理时间,大家最关心的指标之三

Transfer rate: 263.02 [Kbytes/sec] received    //平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题

 
  • 这段表示网络上消耗的时间的分解

  

  • 这段是每个请求处理时间的分布情况,50%的处理时间在273ms内,66%的处理时间在289ms内...,重要的是看90%的处理时间。

  

关于登录的问题


有时候进行压力测试需要用户登录,怎么办?
请参考以下步骤:

  1. 先用账户和密码登录后,用开发者工具找到标识这个会话的Cookie值(Session ID)记下来
  2. 如果只用到一个Cookie,那么只需键入命令:
    ab -n 100 -C key=value http://test.com/

    如果需要多个Cookie,就直接设Header:
    ab -n 100 -H “Cookie: Key1=Value1; Key2=Value2” http://test.com/

总结


总的来说ab工具ab小巧简单,上手学习较快,可以提供需要的基本性能指标,但是没有图形化结果,不能监控。因此ab工具可以用作临时紧急任务和简单测试。
同类型的压力测试工具还有:webbench、siege、http_load等

参考网址:http://www.jianshu.com/p/43d04d8baaf7

超实用压力测试工具-ab工具的更多相关文章

  1. httpd的压力测试工具-ab工具使用案例

    httpd的压力测试工具-ab工具使用案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.   一.httpd自带的工具程序 事实上,在我们安装完Apache之后,它默认就会给我们安 ...

  2. Web进行压力测试的小工具

    在Linux下对Web进行压力测试的小工具有很多,比较出名的有AB.虽然AB可以运行在windows下,但对于想简单界面操作的朋友有点不太习惯.其实vs.net也提供压力测试功能但显然显得太重了,在测 ...

  3. JMeter压力测试和性能测试工具

    Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试,它最初被设计用于Web应用测 试但后来扩展到其他测试领域. 它可以用于测试静态和动态资源例如静态文件 ...

  4. CentOS 6.7平台nginx压力测试(ab/webbench)

    压力测试工具一:webbench 1.安装 wget http://home.tiscali.cz/~cz210552/distfiles/webbench-1.5.tar.gz tar zxvf w ...

  5. Web压力测试 ApacheBench(ab)

    ApacheBench命令原理 ab命令会创建很多的并发访问线程,模拟多个访问者同时对某一URL地址进行访问.它的测试目标是基于URL的,因此,既可以用来测试Apache的负载压力,也可以测试ngin ...

  6. 压力测试 mac ab

    apache ab:http://blog.chinaunix.net/uid-20382003-id-3032167.html 简单用法: ab -n 3000 -c 3000 http://www ...

  7. 压力测试 Apache ab

    https://www.jianshu.com/p/166a4ea8aade https://httpd.apache.org/docs/2.4/programs/ab.html 安装: 按照提示安装 ...

  8. 压力测试工具集合(ab,webbench,Siege,http_load,Web Application Stress)

    压力测试工具集合(ab,webbench,Siege,http_load,Web Application Stress) 1 Apache附带的工具ab ab的全称是ApacheBench,是Apac ...

  9. PHP性能:序——谈ab(Apache Bench)压力测试工具

    PHP性能:序——谈ab(Apache Bench)压力测试工具 ab(Apache  Bench)是啥? ab是Apache自带的一个压力测试软件,可以通过ab命令和选项对某个URL进行压力测试.a ...

随机推荐

  1. 检测内存泄露:Instruments中的Leaks

    前言 如果要检测内存泄露,我们会使用Xcode7自带的Instruments中的Leaks工具来检测. 现在的开发环境是ARC,所以很少会出现内存泄漏的情况. 不过我们一定要养好码代码的规范性. 例如 ...

  2. codeigniter中base_url和site_url

    首先在网站中使用如下的语句: site_url(‘manage/articleAdd’): 1 <?php echo site_url('manage/articleAdd');?> ba ...

  3. 1. python中的随机函数

         本系列不会对python语法,理论作详细说明:所以不是一个学习教材:详细查考Vamei 大神:通俗易懂:是一个很好(基础-中级-高级)的学习教程.而这里只是我一个学习python的某些专题的 ...

  4. setw和setfill控制输出间隔

    在C++中,setw(int n)用来控制输出间隔.例如:cout<<'s'<<setw(8)<<'a'<<endl;则在屏幕显示s a //s与a之间 ...

  5. java 面试每日一题4

    题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?  1.程序分析:可填在百位.十位.个位的数字都是1.2.3.4.组成所有的排列后再去 掉不满足条件的排列. publ ...

  6. c++map的用法 分类: POJ 2015-06-19 18:36 11人阅读 评论(0) 收藏

    c++map的用法 分类: 资料 2012-11-14 21:26 10573人阅读 评论(0) 收藏 举报 最全的c++map的用法 此文是复制来的0.0 1. map最基本的构造函数: map&l ...

  7. 基于clahe的图像去雾

    基于clahe的图像去雾     通过阅读一些资料,我了解到clahe算法对图像去雾有所价值,正好opencv中有了实现,拿过来看一看.   但是现在实现的效果还是有所差异 #);    clahe] ...

  8. Python学习笔记-Day3-python内置函数

    python内置函数 1.abs    求绝对值 2.all 判断迭代器中的所有数据是否都为true 如果可迭代的数据的所有数据都为true或可迭代的数据为空,返回True.否则返回False 3.a ...

  9. TCP三次握手

      TCP协议下,客户的和服务器的连接过程称为“三次握手”   第一次握手:建立连接时,客户的发送SYN包到服务器,并进入SYN_SEND状态,等待服务器确认. 第二次握手:服务器收到SYN包,必须确 ...

  10. SharePoint自动化系列——Select-option标签的定位方法总结

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ C#中通过Selenium定位页面上的select-option结构,尝试了以下几种方法,均没有生 ...