受欢迎的博客标签

ab并发负载压力测试

Published

0、安装ab压力测试软件

apt-get update

否则出现错误

 404  Not Found [IP: 100.100.2.148 80]
E: Failed to fetch http://mirrors.cloud.aliyuncs.com/ubuntu/pool/main/a/apache2/apache2-utils_2.4.29-1ubuntu4.14_amd64.deb  404  Not Found [IP: 100.100.2.148 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

 

 apt-get update  --fix-missing

#查看版本

# ab -V
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/

 

Usage: ab [options] [http[s]://]hostname[:port]/path

 

Example1

ab -n 800 -c 800  http://localhost:5999/
ab -n 800 -c 800  http://192.168.0.10/ 
(-n发出800个请求,-c模拟800并发,相当800人同时访问,后面是测试url)

ab -c 1000 -n 10000 http://192.168.2.38/  #尾部最后一个“/”不能少,否则提示:ab: invalid URL
  
# -c指定1000并发,-n指定总10000次,相当于1000个人访问10次。
# -k 是否开启长连接
Server Software:        nginx/1.8.1  #服务器信息和版本
Server Hostname:        192.168.2.38 #服务器的域名
Server Port:            80 #端口

Document Path:          / #访问的路径
Document Length:        612 bytes #文档的大小为 612 bytes(此为http响应的正文长度)

Concurrency Level:      1000 #并发请求数
Time taken for tests:   0.287 seconds #整个测试持续的时间,默认秒
Complete requests:      1000 #完成的请求数
Failed requests:        0 #失败的请求书
Write errors:           0 #网络连接写入错误数
Total transferred:      844000 bytes #传输的总数据量
HTML transferred:       612000 bytes #传输的HTML内容传输量
Requests per second:    3485.11 [#/sec] (mean) #平均每秒请求数
Time per request:       286.935 [ms] (mean) #所有用户都请求一次的平均时间
Time per request:       0.287 [ms] (mean, across all concurrent requests) #单个用户请求一次的时间
Transfer rate:          2872.49 [Kbytes/sec] received #传输速率

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   84   4.1     84      94
Processing:    86   99   6.6    100     109
Waiting:        0   83  16.2     84     108
Total:         95  183   7.4    182     195

#所有服务请求的百分比占用时间,这里50%的请求用时182ms,一般看90%的部分
Percentage of the requests served within a certain time (ms)
  50%    182
  66%    188
  75%    191
  80%    192
  90%    193
  95%    194
  98%    194
  99%    194
 100%    195 (longest request)

 

ab -t 60 -c 100  http://localhost:5999/
ab -t 60 -c 100 http://192.168.0.10/ 
在60秒内发请求,一次100个请求。 

https://www.cnblogs.com/nulige/p/9370063.html