ab命令原理

ab命令会创建很多的并发访问线程,模拟多个访问者同时对某一URL进行访问。它的测试目标是基于URL的,因此,既可以用来测试Apache的负载压力,也可以测试nginx、lighthttp、IIS等其它Web服务器的压力

ab命令对发出负载的计算机要求很低,既不会占用很多CPU,也不会占用太多的内存,但却会给目标服务器造成巨大的负载,因此是某些DDOS攻击之 必备良药,老少皆宜。自己使用也须谨慎。否则一次上太多的负载,造成目标服务器直接因内存耗光死机,而不得不硬重启,得不偿失。

Apache自带压力测试工具ab用法简介:

ab的全称是ApacheBench,是Apache附带的一个小工具,专门用于HTTP Server的benchmark testing,可以同时模拟多个并发请求。
在这个例子的一开始,我执行了这样一个命令ab -n 10 -c 10 http://www.google.com/。这个命令的意思是启动ab,向www.google.com发送10个请求(-n 10) ,并每次发送10个请求(-c 10)——也就是说一次都发过去了。跟着下面的是ab输出的测试报告,红色部分是我添加的注释。*

键入命令: 
ab -n 800 -c 800  http://192.168.0.10/ 
(-n发出800个请求,-c模拟800并发,相当800人同时访问,后面是测试url)

ab -t 60 -c 100 http://192.168.0.10/ 
在60秒内发请求,一次100个请求。 
  
//如果需要在url中带参数,这样做 
ab -t 60 -c 100 -T "text/plain" -p p.txt http://192.168.0.10/hello.html 
p.txt 是和ab.exe在一个目录 
p.txt 中可以写参数,如  p=wdp&fq=78

结果说明: 

D:\apahce\bin>ab.exe -n 10 -c 10 http://www.google.com/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking www.google.com (be patient).....done
Server Software: gws
Server Hostname: www.google.com
Server Port: 80
Document Path: /
Document Length: 4941 bytes
Concurrency Level: 10
Time taken for tests: 5.218750 seconds//**整个测试持续的时间**
Complete requests: 10//**完成的请求数量**
Failed requests: 9//**失败的请求数量**
(Connect: 0, Length: 9, Exceptions: 0)
Write errors: 0
Total transferred: 52730 bytes**整个场景中的网络传输量**
HTML transferred: 49540 bytes**整个场景中的HTML内容传输量**
Requests per second: 1.92 [#/sec] (mean) **大家最关心的指标之一,相当于LR中的每秒事务数,后面括号中的mean表示这是一个平均值**
Time per request: 5218.750 [ms] (mean) *大家最关心的指标之二,相当于LR中的平均事务响应时间,后面括号中的mean表示这是一个平均值**
Time per request: 521.875 [ms] (mean, across all concurrent requests)
Transfer rate: 9.77 [Kbytes/sec] received*平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题**
Connection Times (ms)
min mean[+/-sd] median max
Connect: 187 488 257.6 437 921
Processing: 312 1673 1204.4 1547 3985
Waiting: 296 1668 1206.3 1546 3984
Total: 593 2162 1432.6 1890 4906
**下面的内容为整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于**毫秒,60%的用户响应时间小于**毫秒,最大的响应时间小于 **毫秒**
Percentage of the requests served within a certain time (ms)
50% 1890
66% 2406
75% 3093
80% 3984
90% 4906
95% 4906
98% 4906
99% 4906
100% 4906 (longest request)
格式:
./ab [options] [http://]hostname[:port]/path
参数:
-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) 

Apache自带压力测试工具ab用法简介的更多相关文章

  1. apache自带压力测试工具ab的使用及解析

    当你搭建了apache服务器并在上面部署了web网站,在网站运行前,为了使apache服务器的性能得到更好的应用,我们可以先对其进行压力测试.进行压力测试其实非常简单,我们也不用再额外下载安装什么测试 ...

  2. Apache自带压力测试工具----linux环境中ab命令简介及结果分析

    ab(apache bench)是apache下的一个工具,主要用于对web站点做压力测试, 基础用法: 其中-c选项为一次发送的请求数量,及并发量.-n选项为请求次数. 实验测试: [dev@web ...

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

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

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

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

  5. linux下web压力测试工具ab使用及详解

    APACHE自带的测试工具AB(apache benchmark).在APACHE的bin目录下.格式: ./ab [options] [http://]hostname[:port]/path参数: ...

  6. Apache中压力测试工具ab的操作说明

    1.压力测试工具ab(ApacheBench)的简单说明 1)     网站性能压力测试是性能调优过程中必不可少的一环.只有让服务器处在高压情况下才能真正体现出各种设置所暴露的问题.Apache中有个 ...

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

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

  8. Mac下的Web性能压力测试工具:ab(ApacheBench)

    Web开发,少不了的就是压力测试,它是评估一个产品是否合格上线的基本标准. ab是一种用于测试Apache超文本传输协议(HTTP)服务器的工具.apache自带ab工具,可以测试Apache.IIS ...

  9. 压力测试工具ab及centos下单独安装方法

    压力测试工具Ab简介 Apache安装包中自带的压力测试工具 Apache Benchmark(简称ab) 简单易用,这里就采用 ab作为压力测试工具了. 1.独立安装 ab运行需要依赖apr-uti ...

随机推荐

  1. FusionCharts使用问题及解决方法(二)-FusionCharts常见问题大全

    在上文中,我们介绍了FusionCharts常见问题(FAQ)的解决方法,本文将一同讨论FusionCharts使用者面临的一些复杂问题的解决方法. 如何启用JavaScript调试模式? 要启用Ja ...

  2. 单词接龙(dragon)

    单词接龙(dragon) 题目描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中出现两次) ...

  3. Naive Bayes在mapreduce上的实现(转)

    Naive Bayes在mapreduce上的实现 原文地址 http://www.cnblogs.com/sunrye/p/4553732.html Naive Bayes是比较常用的分类器,因为思 ...

  4. 转:web_custom_request应用示例

    LoadRunner提供的web_custom_request函数可以用于实现参数的动态生成.在LoadRunner中,web_reg_save_param和custom_request都常于处理参数 ...

  5. HDU 5531 Rebuild

    2015 ACM/ICPC 长春现场赛 E题 三分. 如果节点个数是奇数,那么直接列方程可以求解,因为,如果第一个圆半径变大,必然导致最后一个圆的半径变大, 所以,节点是奇数的时候,要么无解,要么只有 ...

  6. 使用Spring框架的好处(转帖)

    http://blog.csdn.net/cynhafa/article/details/6205361 在SSH框假中spring充当了管理容器的角色.我们都知道Hibernate用来做持久层,因为 ...

  7. Keil 二进制数输入宏

    源:http://hi.baidu.com/skystalker/item/e7679cd79c6f751220e250c1?qq-pf-to=pcqq.c2c 在C语言中有十进制,十六进制,八进制; ...

  8. PAT (Advanced Level) 1082. Read Number in Chinese (25)

    模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  9. HDU 3265 Posters

    矩形面积并,一个拆成四个 #include<cstdio> #include<cstring> #include<cmath> #include<map> ...

  10. E/WindowState(643): getStack: Window{33f867f8 u0 Starting com.xxxxxx.ooooo}

    Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% ...