网站压力测试工具-ab工具

1.压力测试相关概念:

 吞吐率(Requests per second)

概念:服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。
计算公式:总请求数 / 处理完成这些请求数所花费的时间,即
Request per second = Complete requests / Time taken for tests

并发连接数(The number of concurrent connections)
概念:某个时刻服务器所接受的请求数目,简单的讲,就是一个会话。 

并发用户数(The number of concurrent users,Concurrency Level)

概念:要注意区分这个概念和并发连接数之间的区别,一个用户可能同时会产生多个会话,也即连接数。

 用户平均请求等待时间(Time per request)

计算公式:处理完成所有请求数所花费的时间/ (总请求数 / 并发用户数),即
Time per request = Time taken for tests /( Complete requests / Concurrency Level)

 服务器平均请求等待时间(Time per request: across all concurrent requests)

计算公式:处理完成所有请求数所花费的时间 / 总请求数,即
Time taken for / testsComplete requests
可以看到,它是吞吐率的倒数。
同时,它也=用户平均请求等待时间/并发用户数,即
Time per request / Concurrency Level

 2.ab工具简介:

ab是apache bench的缩写,是Apache自带的压力测试工具,主要对web服务器进行网站访问压力测试。

3.安装方法:
[root@localhost yum.repos.d]# yum install -y httpd-tools
已加载插件:langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd-tools.x86_64.0.2.4.6-88.el7.ns7.01 将被 安装
--> 解决依赖关系完成

依赖关系解决

==============================================================================================================
Package 架构 版本 源 大小
==============================================================================================================
正在安装:
httpd-tools x86_64 2.4.6-88.el7.ns7.01 Nk7.6 90 k

事务概要
==============================================================================================================
安装 1 软件包

总下载量:90 k
安装大小:169 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : httpd-tools-2.4.6-88.el7.ns7.01.x86_64 1/1
验证中 : httpd-tools-2.4.6-88.el7.ns7.01.x86_64 1/1

已安装:
httpd-tools.x86_64 0:2.4.6-88.el7.ns7.01

完毕!

#查看ab版本信息
[root@localhost yum.repos.d]# ab -V
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

4.用法:
ab [options] [http[s]://]hostname[:port]/path

#部分选项使用说明
-k 启用KeepAlive功能,在一次会话中执行多个请求
-r 尽可能多的发送请求
-n 请求访问数量
-c 并发数

#示例:
[root@localhost yum.repos.d]# ab -kr -n 1000 -c 100 https://www.cnblogs.com/zhangyanjiang
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.cnblogs.com (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:                            #服务器软件
Server Hostname: www.cnblogs.com                    #服务器域名
Server Port: 443 #服务器端口
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128

Document Path: /zhangyanjiang                      #访问文件路径
Document Length: 3902 bytes

Concurrency Level: 100                           #访问并发数,为参数-c所对应的值
Time taken for tests: 13.180 seconds                     #测试总访问时间
Complete requests: 1000                        #总访问数量,为参数-n所对应的值
Failed requests: 0                            #失败访问数
Write errors: 0
Keep-Alive requests: 0
Total transferred: 4040000 bytes
HTML transferred: 3902000 bytes
Requests per second: 75.87[#/sec] (mean)         #每秒钟处理的访问请求数量,经常称之为吞吐率
Time per request: 1318.043 [ms] (mean)                  #用户平均请求等待时间
Time per request: 13.180 [ms] (mean, across all concurrent requests)      #服务器平均请求等待时间
Transfer rate: 299.33 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 220 839 2188.1 267 9309
Processing: 78 102 17.0 98 210
Waiting: 77 98 15.1 95 193
Total: 301 941 2187.5 367 9416

Percentage of the requests served within a certain time (ms)
50% 367
66% 384
75% 397
80% 404
90% 443
95% 9332
98% 9369
99% 9390
100% 9416 (longest request)

猜你喜欢

转载自www.cnblogs.com/zhangyanjiang/p/12081274.html