Apache ab压测工具使用

ab是一种用于测试Apache超文本传输协议(HTTP)服务器的工具。apache自带ab工具,可以测试
apache、IIs、tomcat、nginx等服务器

linux 安装

yum -y install httpd-tools

ab手册

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.
    -m method       Method name
    -h              Display usage information (this message)
    -I              Disable TLS Server Name Indication (SNI) extension
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol
                    (TLS1, TLS1.1, TLS1.2 or ALL)
    -E certfile     Specify optional client certificate chain and private key

直接看操作手册可能有点上头,我给大家翻译了一些

参数信息 变量 说明
-n request 请求总数
-c concurrency 并发数
-t timelimit 用于基准测试的最长时间
-s timeout 请求超时时间,默认30s
-b windowsize TCP发送/接收缓冲区的大小,以字节为单位
-B address 请求地址
-p postfile post请求体(是一个文件)
-u putfile put请求体(是一个文件)
-T contentType post/put请求的content-type。eg:'application/json';'applicationx-www-form-urlencoded'
-v verbosity 设置显示信息的详细程度 - 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出。
-w 在HTML表格中打印结果
-i 执行HEAD请求,而不是GET请求
-x attributes 要作为表属性插入的字符串
-y attributes 作为tr属性插入的字符串
-z attributes 作为td属性插入的字符串
-C attributes 添加cookie eg. 'Apache=1234'
-H attributes 添加Header eg.'Accept-Encoding: gzip'
-k 使用HTTP KeepAlive功能
-g filename 将收集到的数据输出到gnuplot格式文件。
-e filename 结果输出到CSV文件
-r 发生socker错误时不退出
-h 不展示用例信息

压测GET请求

请求地址:http://127.0.0.1:8074/raindrop/snowflake
并发数 100
请求总数 1000

ab -c 100 -n 1000 http://127.0.0.1:8074/raindrop/snowflake

结果

Server Software:        
Server Hostname:        127.0.0.1
Server Port:            8074

Document Path:          /raindrop/snowflake
Document Length:        80 bytes

Concurrency Level:      100
Time taken for tests:   0.465 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      199000 bytes
HTML transferred:       80000 bytes
Requests per second:    2152.84 [#/sec] (mean)
Time per request:       46.450 [ms] (mean)
Time per request:       0.465 [ms] (mean, across all concurrent requests)
Transfer rate:          418.37 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   3.2      1      17
Processing:     3   43  62.2     23     336
Waiting:        3   36  58.7     18     324
Total:          7   45  61.8     27     337

Percentage of the requests served within a certain time (ms)
  50%     27
  66%     29
  75%     34
  80%     36
  90%    212
  95%    222
  98%    233
  99%    247
 100%    337 (longest request)

通过结果可以看出压测的一些信息,比如最小链接时间,最长链接时间,请求响应的信息等。

发送POST请求

请求地址:https://www.test.com/user/secret/listPage
并发数:100
请求总数:1000
content-type:application/json
请求体:{}

POST请求需要将请求体放到指定的文件中,新建一个post.txt文件,文件内容是请求体。

 ab -c 100 -n 1000 -p post.txt -T 'application/json' https://www.test.com/user/secret/listPage

压测结果

Server Software:        nginx/1.16.1
Server Hostname:        www.test.com
Server Port:            443
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
Server Temp Key:        ECDH P-256 256 bits
TLS Server Name:        www.zhengoole.com

Document Path:          /user/secret/listPage
Document Length:        153 bytes

Concurrency Level:      100
Time taken for tests:   16.345 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      371000 bytes
Total body sent:        157000
HTML transferred:       153000 bytes
Requests per second:    61.18 [#/sec] (mean)
Time per request:       1634.501 [ms] (mean)
Time per request:       16.345 [ms] (mean, across all concurrent requests)
Transfer rate:          22.17 [Kbytes/sec] received
                        9.38 kb/s sent
                        31.55 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      165 1167 1338.3    490    6001
Processing:    58  252 324.6    101    1489
Waiting:       58  250 324.0     99    1488
Total:        226 1419 1324.1    877    6113

Percentage of the requests served within a certain time (ms)
  50%    877
  66%   1566
  75%   1934
  80%   2073
  90%   3105
  95%   4926
  98%   5090
  99%   6028
 100%   6113 (longest request)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,542评论 6 504
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,822评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,912评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,449评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,500评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,370评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,193评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,074评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,505评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,722评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,841评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,569评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,168评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,783评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,918评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,962评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,781评论 2 354