简单的压力测试工具 ab

ab Apache HTTP server benchmarking tool,可以用作简单的http压力测试工具,在有些时候在没有运维组帮助的条件下我们可以完成一些压力测试。虽然使用简单但是功能却不简单,应该是很强大。

它的功能包括:

1. 单线程多次请求

2. 并发多次请求

3. 用户认证信息请求

4. 带Cookie信息请求

5. 设置发送数据大小

6. 支持 SSL/TLS 协议

7. 自定义header

8. PUT file

9. 报表

10. csv报表

… …

太多了,强大到所有类型的http协议压力测试都可以实现。感兴趣的同学可以看一下man ab。但使用起来却出奇的简单。 比如:

# 请求http://www.renren.com/home 2000次

ab -n 2000 http://www.renren.com/home

output:

This is ApacheBench, Version 2.3

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.renren.com (be patient)

Completed 200 requests

Completed 400 requests

Completed 600 requests

Completed 800 requests

Completed 1000 requests

Completed 1200 requests

Completed 1400 requests

Completed 1600 requests

Completed 1800 requests

Completed 2000 requests

Finished 2000 requests

Server Software: nginx/1.1.7

Server Hostname: www.renren.com

Server Port: 80

Document Path: /home

Document Length: 134 bytes

Concurrency Level: 1

Time taken for tests: 41.018 seconds

Complete requests: 2000

Failed requests: 0

Write errors: 0

Non-2xx responses: 2000

Total transferred: 724000 bytes

HTML transferred: 268000 bytes

Requests per second: 48.76 [#/sec] (mean)

Time per request: 20.509 [ms] (mean)

Time per request: 20.509 [ms] (mean, across all concurrent requests)

Transfer rate: 17.24 [Kbytes/sec] received

Connection Times (ms)

min mean[+/-sd] median max

Connect: 1 3 67.2 2 3007

Processing: 8 17 71.5 11 2270

Waiting: 8 17 71.5 11 2270

Total: 10 20 98.0 13 3017

Percentage of the requests served within a certain time (ms)

50% 13

66% 13

75% 14

80% 14

90% 15

95% 17

98% 45 #百分之98的请求时间小于45ms ,还不错

99% 195

100% 3017 (longest request)

上面的内容很多,Requests per second: 48.76 [#/sec] (mean) ; Time per request: 20.509 [ms] (mean)这是我们关心的。表示每秒可以请求48次,平均每次请求20ms。以上内容是在我本地做的测试。

当然,还有其他用法如下:

# 20个线程,请求总数2000次

ab -n 2000 -c 20 http://www.renren.com/home

#测试需要cookie的请求

ab -n 2000 -c 20 -C t=ticket http://www.renren.com/home

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>