Linux ab 压力测试

 

ab 是 Apache 附带的接口压力测试功能,非常简单易用。在测试服务端程序自身运行时长和跨区测试接口反馈时长时非常有用。

下载

CentOS

$ sudo yum install -y httpd

Ubuntu

$ sudo apt install -y apache2-utils

使用

$ ab -c 10 -n 100 http://ip-api.com/json

参数

  • -c: 表示并发数
  • -n: 表示请求总数

结果

> $ ab -c 10 -n 100 http://ip-api.com/json
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking ip-api.com (be patient).....done


Server Software:
Server Hostname:        ip-api.com
Server Port:            80

Document Path:          /json
Document Length:        306 bytes

Concurrency Level:      10
Time taken for tests:   6.184 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      46200 bytes
HTML transferred:       30600 bytes
Requests per second:    16.17 [#/sec] (mean)
Time per request:       618.369 [ms] (mean)
Time per request:       61.837 [ms] (mean, across all concurrent requests)
Transfer rate:          7.30 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    3   1.1      3       6
Processing:   528  572  58.4    550     889
Waiting:      528  571  58.7    549     888
Total:        531  575  58.3    552     891

Percentage of the requests served within a certain time (ms)
  50%    552
  66%    565
  75%    574
  80%    600
  90%    635
  95%    656
  98%    890
  99%    891
 100%    891 (longest request)

结果详解

Server Software:        web服务器软件及版本
Server Hostname:        请求的地址
Server Port:            请求的端口

Document Path:          请求的页面路径
Document Length:        页面大小

Concurrency Level:      并发数
Time taken for tests:   测试总共花费的时间
Complete requests:      完成的请求数
Failed requests:        失败的请求数
Write errors:           写入错误
Total transferred:      总共传输字节数,包含http的头信息等
HTML transferred:       html字节数,实际的页面传递字节数
Requests per second:    每秒处理的请求数,服务器的吞吐量(重要)
Time per request:       平均数,用户平均请求等待时间
Time per request:       服务器平均处理时间
Transfer rate:          平均传输速率(每秒收到的速率)

Time per request 是我们测试接口时长时非常关键的字段。

原文地址:https://www.cnblogs.com/lxwphp/p/15452875.html