Apache服务器自带ab压力测试工具,可以很方便的用来进行测试。
首先找到apache安装目录的bin目录,找到ab.exe
使用windows cmd进入到ab.exe所在目录
然后使用命令 ab -n 1000 -c 100 http://localhost:8080/JDBC/index.jsp
http://localhost:8080/JDBC/index.jsp是我建的的一个java jdbc的demo,是进行测试的页面
看到如下测试结果
这里就完成了一次测试,现在介绍一下上面命令的含义
ab 的用法是:ab [options] [http://]hostname[:port]/path
ab常用参数的介绍:
-n :总共的请求执行数,缺省是1;
-c: 并发数,缺省是1;
-t:测试所进行的总时间,秒为单位,缺省50000s
-p:POST时的数据文件
-w: 以HTML表的格式输出结果
所以上面命令的含义是,访问http://localhost:8080/JDBC/index.jsp页面1000次,100并发同时执行,就相当于100个人同时访问该页面。
测试结果参数分析
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (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: Apache-Coyote/1.1 //平台apache 版本1.1
Server Hostname: localhost //服务器主机名
Server Port: 8080 //服务器端口
Document Path: /JDBC/index.jsp //测试的页面文档
Document Length: 3203 bytes //文档大小
Concurrency Level: 100 //并发数
Time taken for tests: 6.355 seconds //整个测试持续的时间
Complete requests: 1000 //完成的请求数量
Failed requests: 0 //失败的请求数量
Total transferred: 3445000 bytes //整个场景中的网络传输量
HTML transferred: 3203000 bytes //整个场景中的HTML内容传输量
Requests per second: 157.35 [#/sec] (mean)//大家最关心的指标之一,用户平均请求等待时
间 ,后面括号中的 mean 表示这是一个平均值
Time per request: 635.521 [ms] (mean)//大家最关心的指标之二,服务器平均请求处理时
间,后面括号中的 mean 表示这是一个平均值
Time per request: 6.355 [ms] (mean, across all concurrent requests)//每个请求实际
运行时间的平均值
Transfer rate: 529.37 [Kbytes/sec] received//平均每秒网络上的流量,可以帮助排除
是否存在网络流量过大导致响应时间延长的问题
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 6 14.7 0 172
Processing: 16 592 204.8 562 1452
Waiting: 16 428 217.2 437 1452
Total: 31 598 204.8 563 1467
Percentage of the requests served within a certain time (ms)
50% 563
66% 640
75% 718
80% 749
90% 906
95% 968
98% 1093
99% 1140
100% 1467 (longest request)
//整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间
小于563 毫秒,60% 的用户响应时间小于6407 毫秒,最大的响应时间小于1467 毫秒
由于对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转
处理的,所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求
数
以上最重要的两个指标是Requests per second和Time per request,用户平均请求等待时和服务器平均请求处理时
以上是一次测试,然后调整参数再继续测试。