Linux环境下如何实用ab命令实现接口的性能测试

1. 安装:sudo apt-install apache2-utils
2. 用法
(1)基本参数:
  • -n:共发起的请求数
  • -c:每一次发送的请求数(并发数)
  • -vn:当n>2时,可以显示发送的http请求头和响应的http头的内容。并且,n越大显示的内容会越全,比如,-v4。
比如: ab-n10000 -c100 -v4 -H'Content-Type: application/json' -p'test.json' 'http://192.168.1.36:8080/vtboss/service/account',表示:以并发100连续请求100次。

(2)eg:(以并发1请求1次)

ab -n1 -c1 -H'Content-Type: application/json' -p'test.json' 'http://192.168.1.36:8080/vtboss/service/account'

打印结果如下:
This is ApacheBench, Version 2.3 <$Revision: 655654$>
Copyright 1996 Adam Twiss, Zeus TechnologyLtd, http://www.zeustech.net/
Licensed to The Apache SoftwareFoundation, http://www.apache.org/

Benchmarking 192.168.1.36 (be patient).....done


Server Software:       Apache-Coyote/1.1
Server Hostname:       192.168.1.36
Server Port:           8080

Document Path:         /vtboss/service/account
Document Length:       49bytes

Concurrency Level:     1
Time taken for tests:   0.020seconds
Complete requests:     1
Failed requests:       0
Write errors:          0
Total transferred:     281bytes
Total POSTed:          421
HTML transferred:      49bytes
Requests per second:   49.98 [#/sec](mean)
Time per request:      20.008[ms] (mean)
Time per request:      20.008[ms] (mean, across all concurrent requests)
Transfer rate:         13.72[Kbytes/sec] received
                       20.55kb/s sent
                       34.26kb/s total

Connection Times (ms)
             min mean[+/-sd] median  max
Connect:          0.0          1
Processing:   19  19  0.0    19     19
Waiting:      19  19  0.0    19     19
Total:        20  20  0.0    20     20


ab -n1 -c1 -v4 -H'Content-Type: application/json' -p'test.json' 'http://192.168.1.36:8080/vtboss/service/account'

打印结果如下:
This is ApacheBench, Version 2.3 <$Revision: 655654$>
Copyright 1996 Adam Twiss, Zeus TechnologyLtd, http://www.zeustech.net/
Licensed to The Apache SoftwareFoundation, http://www.apache.org/

Benchmarking 192.168.1.36 (be patient)...INFO: POST header==
---
POST /vtboss/service/account HTTP/1.0
Content-length: 234
Content-type: text/plain
Content-Type: application/json
Host: 192.168.1.36:8080
User-Agent: ApacheBench/2.3
Accept: */*


---
LOG: header received:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=78D09B30C746498E328B1E3EBB40797E;Path=/vtboss
Content-Type: text/html;charset=UTF-8
Content-Length: 49
Date: Thu, 13 Nov 2014 09:30:26 GMT
Connection: close

{"id":0,"jsonrpc":"2.0","result":{"accounts":[]}}
LOG: Response code = 200
..done


Server Software:       Apache-Coyote/1.1
Server Hostname:       192.168.1.36
Server Port:           8080

Document Path:         /vtboss/service/account
Document Length:       49bytes

Concurrency Level:     1
Time taken for tests:   0.009seconds
Complete requests:     1
Failed requests:       0
Write errors:          0
Total transferred:     281bytes
Total POSTed:          421
HTML transferred:      49bytes
Requests per second:   107.72[#/sec] (mean)
Time per request:      9.283[ms] (mean)
Time per request:      9.283[ms] (mean, across all concurrent requests)
Transfer rate:         29.56[Kbytes/sec] received
                       44.29kb/s sent
                       73.85kb/s total

Connection Times (ms)
             min mean[+/-sd] median  max
Connect:          0.0          1
Processing:       0.0          9
Waiting:          0.0          8
Total:            0.0          9

(3)关注点
  • 失败率
  • 单个并发的平均响应时间
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值