Linux工具使用

ab

ab (apache bench)是 apache 下的一个工具,主要用于做 web 站点的压力测试

debian 安装:apt install apache2-utils

CentOS 安装:yum -y install httpd-tools

查看安装位置:which ab

命令详解:

#例如
# ab -n 请求次数 -c 并发数 访问地址
ab -n 1000 -c 100  http://192.168.31.15/index.html  # 表示请求1000次中有100并发

结果:

root@debian:/etc/nginx/sites-enabled# ab -n 1000 -c 100 http://192.168.31.15/index.html
his is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.31.15 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        openresty/1.15.8.1
Server Hostname:        192.168.31.15
Server Port:            80

Document Path:          /index.html
Document Length:        25778 bytes

Concurrency Level:      100                 # 并发数
Time taken for tests:   1.098 seconds       # 请求时间
Complete requests:      1000                # 成功请求次数
Failed requests:        0                   # 失败的请求
Total transferred:      26020000 bytes
HTML transferred:       25778000 bytes
Requests per second:    910.87 [#/sec] (mean)
Time per request:       109.786 [ms] (mean)
Time per request:       1.098 [ms] (mean, across all concurrent requests)
Transfer rate:          23145.25 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    4   1.6      4       9
Processing:     5  104 265.3     16     911
Waiting:        2   96 263.7      9     903
Total:         12  108 264.9     20     916

Percentage of the requests served within a certain time (ms)
  50%     20
  66%     22
  75%     23
  80%     23
  90%    881
  95%    902
  98%    914
  99%    915
 100%    916 (longest request)