Skip to content

天楚锐齿

人工智能 云计算 大数据 物联网 IT 通信 嵌入式

天楚锐齿

  • 下载
  • 物联网
  • 云计算
  • 大数据
  • 人工智能
  • Linux&Android
  • 网络
  • 通信
  • 嵌入式
  • 杂七杂八

ab(Apache Bench)测试http压力和性能

2018-07-19
    ab命令会创建多个并发访问线程,模拟多个访问者同时对某一URL地址进行访问。它的测试目标是基于URL的,因此,它既可以用来测试apache的负载压力,也可以测试nginx、lighthttp、tomcat、IIS等其它Web服务器的压力。ab命令对发出负载的计算机要求很低,它既不会占用很高CPU,也不会占用很多内存。但却会给目标服务器造成巨大的负载,其原理类似CC攻击。自己测试使用也需要注意,否则一次上太多的负载。可能造成目标服务器资源耗完,严重时甚至导致死机。
安装:
$ sudo yum install httpd-tools
$ ab -V
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
使用:
$ 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 at a time 一次产生的请求个数。默认是一次一个。
    -t timelimit    Seconds to max. to spend on benchmarking, This implies -n 50000  测试所进行的最大秒数。其内部隐含值是-n 50000,它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。和-n参数选一个即可。
    -s timeout      Seconds to max. wait for each response, Default is 30 seconds  请求超时时间。
    -b windowsize   Size of TCP send/receive buffer, in bytes  发送接收Buffer大小。
    -B address      Address to bind to when making outgoing connections 绑定地址,默认0.0.0.0。
    -p postfile     File containing data to POST. Remember also to set -T 使用POST时带的内容数据。
    -u putfile      File containing data to PUT. Remember also to set -T 使用PUT时带的内容数据。
    -T content-type Content-type header to use for POST/PUT data, eg. ‘application/x-www-form-urlencoded’, Default is ‘text/plain’ 在HTTP头Content-type字段中POST或PUT的类型。
    -v verbosity    How much troubleshooting info to print  设置显示信息的详细程度:4或更大值会显示头信息,3或更大值可以显示响应代码(404,200等),2或更大值可以显示警告和其他信息。
    -w              Print out results in HTML tables  输出HTML格式的结果。
    -i              Use HEAD instead of GET  仅执行HEAD请求,而不发送实际GET。
    -x attributes   String to insert as table attributes 设置<table>属性的字符串。
    -y attributes   String to insert as tr attributes 设置<tr>属性的字符串。
    -z attributes   String to insert as td or th attributes 设置<td>属性的字符串。
    -C attribute    Add cookie, eg. ‘Apache=1234’. (repeatable) 对请求附加一个Cookie:行。其典型形式是name=value的一个参数对,此参数可以重复。
    -H attribute    Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’ Inserted after all normal header lines. (repeatable) 对请求附加额外的头信息。此参数的典型形式是一个有效的头信息行,其中包含了以冒号分隔的字段和值的对(如,”Accept-Encoding:zip/zop;8bit”)。
    -A attribute    Add Basic WWW Authentication, the attributes are a colon separated username and password. 对服务器提供BASIC认证信任。用户名和密码由一个:隔开,并以base64编码形式发送。无论服务器是否需要(即,是否发送了401认证需求代码),此字符串都会被发送。
    -P attribute    Add Basic Proxy Authentication, the attributes are a colon separated username and password. 对一个中转代理提供BASIC认证信任。用户名和密码由一个:隔开,并以base64编码形式发送。无论服务器是否需要(即, 是否发送了401认证需求代码),此字符串都会被发送。
    -X proxy:port   Proxyserver and port number to use 对请求使用代理服务器,带代理服务器地址端口。
    -V              Print version number and exit 输出版本信息。
    -k              Use HTTP KeepAlive feature 启用HTTP KeepAlive功能,即在一个HTTP会话中执行多个请求。默认时,不启用KeepAlive功能。
    -d              Do not show percentiles served table. 不显示”percentage served within XX [ms] table”的消息(为以前的版本提供支持)。
    -S              Do not show confidence estimators and warnings.  不显示置信度评估和警告。
    -q              Do not show progress when doing more than 150 requests 如果处理的请求数大于150,ab每处理大约10%或者100个请求时,会在stderr输出一个进度计数。此-q标记可以抑制这些信息。
    -g filename     Output collected data to gnuplot format file. 把所有测试结果写入一个’gnuplot’或者TSV(以Tab分隔的)文件。此文件可以方便地导入到Gnuplot,IDL,Mathematica,Igor甚至Excel中。其中的第一行为标题。
    -e filename     Output CSV file with percentages served 产生一个以逗号分隔的(CSV)文件,其中包含了处理每个相应百分比的请求所需要(从1%到100%)的相应百分比的(以微妙为单位)时间。由于这种格式已经“二进制化”,所以比’gnuplot’格式更有用。
    -r              Don’t exit on socket receive errors.  接收SOCKET错误时不要退出。
    -h              Display usage information (this message) 显示用法。
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers) 指定SSL加密算法。
    -f protocol     Specify SSL/TLS protocol (SSL2, SSL3, TLS1, TLS1.1, TLS1.2 or ALL) 指定SSL加密协议。
结果说明:
$ ab -c 10 -t 30  http://www.baidu.com/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.baidu.com (be patient)
Finished 25 requests
Server Software:        BWS/1.1
Server Hostname:        www.baidu.com
Server Port:            80
Document Path:          /
Document Length:        112108 bytes 表示HTTP响应数据的正文长度。
Concurrency Level:      10  并发用户数
Time taken for tests:   30.165 seconds 表示所有这些请求被处理完成所花费的总时间。
Complete requests:      25  表示总请求数量。
Failed requests:        24  表示失败的请求数量,这里的失败是指请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况。如果接收到的HTTP响应数据的头信息中含有2XX以外的状态码,则会在测试结果中显示另一个名为“Non-2xx responses”的统计项,用于统计这部分请求数,这些请求并不算在失败的请求中。
   (Connect: 0, Receive: 0, Length: 24, Exceptions: 0)
Write errors:           0
Total transferred:      3362681 bytes  表示所有请求的响应数据长度总和,包括每个HTTP响应数据的头信息和正文数据的长度。注意这里不包括HTTP请求数据的长度,仅仅为web服务器流向用户PC的应用层数据总长度。
HTML transferred:       3330995 bytes 表示所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度。
Requests per second:    0.83 [#/sec] (mean)  吞吐率,只用完成了的请求进行计算(25/30.165)。
Time per request:       12066.150 [ms] (mean)
Time per request:       1206.615 [ms] (mean, across all concurrent requests) 平均请求时间(30.165/25)
Transfer rate:          108.86 [Kbytes/sec] received 表示这些请求在单位时间内从服务器获取的数据长度(3362681/30.165)。
Connection Times (ms)  每个请求中连接、处理、等待各部分占用的最小、最大、中值、平均时间(mean)和标准差(+/-sd)
                      min  mean[+/-sd]  median   max
Connect:            7  383  595.6     49         1999
Processing:  3041 8337 4329.3   8134      24639
Waiting:            9  396   546.0     96         1682
Total:          3080 8720  4247.1   8355     24646
Percentage of the requests served within a certain time (ms) 这部分数据用于描述每个请求处理时间的分布情况
  50%   8290
  66%   8758
  75%   9440
  80%   9749
  90%  12148
  95%  15938
  98%  24646
  99%  24646
100%  24646 (longest request)
测试HTTP GET请求:
$ ab -c 10 -t 30  http://www.jianshu.com/search?q=test&page=1&type=note
测试HTTP POST请求:
$ cat post.txt
{“test”:”yes”, “number”:5}
$ ab -c 10 -t 30 -p post.txt -T “application/json” http://api.nohttp.net/upload
等同于执行:
$ curl -H ‘Content-Type:application/json’ -X POST  -d ‘{“test”:”yes”, “number”:5}’  http://api.nohttp.net/upload
测试HTTP PUT请求:
$ cat post.txt
{“test”:”yes”, “number”:5}
$ ab -c 10 -t 30 -u post.txt -T “application/json” http://api.nohttp.net/upload
等同于执行:
$ curl -H ‘Content-Type:application/json’ -X PUT  -d ‘{“test”:”yes”, “number”:5}’  http://api.nohttp.net/upload
测试HTTPS GET请求(POST/PUT内容数据时格式同上):
$ ab -c 10 -t 30  https://www.baidu.com/
等同于执行(-k表示忽略证书校验):
$ curl -k https://www.baidu.com/
963次阅读

Post navigation

前一篇:

中国金融数据月度报表-2018年6月

后一篇:

中国金融数据月度报表-2018年7月

发表评论 取消回复

邮箱地址不会被公开。 必填项已用*标注

个人介绍

需要么,有事情这里找联系方式:关于天楚锐齿

=== 美女同欣赏,好酒共品尝 ===

微信扫描二维码赞赏该文章:

扫描二维码分享该文章:

分类目录

  • Linux&Android (79)
  • Uncategorized (1)
  • 下载 (28)
  • 云计算 (37)
  • 人工智能 (8)
  • 大数据 (24)
  • 嵌入式 (34)
  • 杂七杂八 (34)
  • 物联网 (59)
  • 网络 (23)
  • 通信 (21)

文章归档

近期文章

  • 使用Python渲染OpenGL的.obj和.mtl文件
  • 用LVGL图形库绘制二维码
  • Android使用Messenger和SharedMemory实现跨app的海量数据传输
  • CAN信号的c语言解析代码
  • QT qml下DBus的使用例子

近期评论

  • 硕发表在《使用Android的HIDL+AIDL方式编写从HAL层到APP层的程序》
  • maxshu发表在《使用Android的HIDL+AIDL方式编写从HAL层到APP层的程序》
  • Ambition发表在《使用Android的HIDL+AIDL方式编写从HAL层到APP层的程序》
  • Ambition发表在《使用Android的HIDL+AIDL方式编写从HAL层到APP层的程序》
  • maxshu发表在《Android9下用ethernet 的Tether模式来做路由器功能》

阅读量

  • 使用Android的HIDL+AIDL方式编写从HAL层到APP层的程序 - 16,804次阅读
  • 卸载深信服Ingress、SecurityDesktop客户端 - 12,078次阅读
  • 车机技术之Android Automotive - 6,661次阅读
  • 车机技术之车规级Linux-Automotive Grade Linux(AGL) - 5,861次阅读
  • Linux策略路由及iptables mangle、ip rule、ip route关系及一种Network is unreachable错误 - 5,709次阅读
  • 在Android9下用ndk编译vSomeIP和CommonAPI以及使用例子 - 5,658次阅读
  • linux下的unbound DNS服务器设置详解 - 5,601次阅读
  • linux的tee命令导致ssh客户端下的shell卡住不动 - 4,998次阅读
  • 车机技术之360°全景影像(环视)系统 - 4,897次阅读
  • libwebp(处理webp图像)的安装和使用 - 4,749次阅读

功能

  • 文章RSS
  • 评论RSS

联系方式

地址
深圳市科技园

时间
周一至周五:  9:00~12:00,14:00~18:00
周六和周日:10:00~12:00

标签

android AT命令 centos Hadoop hdfs ip ipv6 kickstart linux mapreduce mini6410 modem OAuth openstack os python socket ssh uboot 内核 协议 安装 嵌入式 性能 报表 授权 操作系统 数据 数据库 月报 模型 汽车 测试 深信服 深度学习 源代码 神经网络 统计 编译 网络 脚本 虚拟机 调制解调器 车机 金融
© 2023 天楚锐齿