压力测试的概念\定义:apache
性能测试Performance Test :是指经过自动化的测试工具模拟多种正常、峰值以及异常负载条件来对系统的各项性能指标进行测试;windows
压力测试 stress testing :是指经过测试系统的瓶颈或者不能接受的性能点,来得到系统能提供的最大服务级别的测试;浏览器
负载测试 Load Test :是指经过测试系统在资源超负荷状况下的表现,才以发现设计上的错误或验证系统的负载能力。服务器
ApacheBench(简称AB)是 Apache 的一款功能强大的测试工具,能够快速测试基于 HTTP 协议全部 Web 页面的最大负载压力,扩展性很是强。并发
下载地址:https://www.apachelounge.com/download/工具
下载后是一个压缩包,解压进入bin目录。性能
cmd模式下执行ab测试
若是有提示信息即为正常状态。设计
# 按请求量测试orm
ab -n 10 -c 10 http://127.0.0.1/
# -n 总共10次请求
# -c 是 concurrency ,模拟10个并发用户,即发起10个并发请求
# 按请求时间测试
ab -t 10 -c 10 http://127.0.0.1/
# -t 是 timelimit 执行测试的时间,单位是秒
# -c 是 concurrency ,模拟10个并发用户,即发起10个并发请求
#######
# 命令说明:
# 经过 ab 工具模拟用户浏览器行为,Get请求
# 别再URL上缺乏 http:// ,否者没法发起请求
结果分析:
E:\Apache24\bin>ab -n 3000 -c 50 http://192.168.199.129:9000/req_test
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Benchmarking 192.168.199.129 (be patient)
Completed 3000 requests
Finished 3000 requests
Server Software: Werkzeug/0.14.1
Server Hostname: 192.168.199.129
Server Port: 9000
Document Path: /req_test
Document Length: 27 bytes
Concurrency Level: 50 # 并发数
Time taken for tests: 27.518 seconds # 总耗时
Complete requests: 3000
Failed requests: 2951 # 失败数量,通常length能够忽略
(Connect: 0, Receive: 0, Length: 2951, Exceptions: 0)
Total transferred: 548002 bytes
HTML transferred: 86002 bytes
Requests per second: 109.02 [#/sec] (mean)
# 每秒平均请求数
Time per request: 458.632 [ms] (mean)
# 请求的平均时间
Time per request: 9.173 [ms] (mean, across all concurrent requests)
# 服务器处理请示的平均时间
Transfer rate: 19.45 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 3.0 1 73
Processing: 35 454 72.2 429 683
Waiting: 4 453 72.1 427 680
Total: 35 455 72.4 430 684
Percentage of the requests served within a certain time (ms)
50% 430
66% 457
75% 499
80% 518
90% 569
95% 592
98% 613
99% 628
100% 684 (longest request)