AB 压力测试

Fork Me On Github
zodream 其他技术 2019年07月
今天使用`google search console` 查看网站收录情况发现有很多链接处于 `发现未收录`状态,才想起用工具进行并发测试。

AB (ApacheBench) 是 Apache 自带的一款功能强大的测试工具,可以快速测试基于 HTTP 协议所有 Web 页面的最大负载压力。

下载地址www.apachelounge.com Apache 2.4.39 Win64

本文以 windows 10 为例,使用 PowerShell 执行命令行

加压下载文件到指定文件夹

打开 PowerShell ,通过 cd 进入 bin 目录

cd D:\zodream\Apache24\bin

主要用到 ab.exe 这个程序

.\ab
-n 总共发起几次请求
-c 并发数
-t 总共执行时间,到时结束所有请求,
-s 最大超时时间,默认30秒
-b TCP 请求发送和接受的字节数
-p POST发送文件
-u PUT发送文件
-T 设置请求头内容类型
-k keep-alive保持连接

最后输入完整网址 带http/https

例如

.\ab -t 10 -c 100 http://zodream.cn/

This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking zodream.cn (be patient)
Finished 18 requests 
# 完成 18个请求

Server Software:        Apache
Server Hostname:        zodream.cn
Server Port:            80

Document Path:          /
Document Length:        24125 bytes
# 请求页面大小

Concurrency Level:      100
# 并发请求数量
Time taken for tests:   10.226 seconds
# 整个测试耗时
Complete requests:      18
# 完成的请求数
Failed requests:        0
# 失败的请求
Total transferred:      1146475 bytes
# 网络传输总量
HTML transferred:       1131655 bytes
# HTML 内容传输量
Requests per second:    1.76 [#/sec] (mean)
# 每秒的请求平均数
Time per request:       56812.761 [ms] (mean)
# 每个请求的平均时间
Time per request:       568.128 [ms] (mean, across all concurrent requests)
# 服务器处理请求的平均时间
Transfer rate:          109.48 [Kbytes/sec] received
# 网络平均转移率

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       11   14   3.8     13      23
Processing:  5051 6250 1257.6   5386    8892
Waiting:       47 1733 922.1   1300    3888
Total:       5063 6264 1256.8   5398    8906

Percentage of the requests served within a certain time (ms)
  50%   5398
  66%   6787
  75%   7830
  80%   7840
  90%   7854
  95%   8906
  98%   8906
  99%   8906
 100%   8906 (longest request)

发现问题

.\ab -n 100 -c 100 http://zodream.cn/blog.html

使用此命令,发现出现 ...apr_pollset_poll: The timeout specified has expired (70007) 这样的错误,大致意思是请求超时了,可以增加 -k 保持连接

.\ab -n 100 -c 100 -k http://zodream.cn/blog.html
点击查看全文
0 499 0