一、Tomcat 性能测试
1. 响应时间
响应时间是指执行某个操作的耗时
大多数情况下,我们需要针对同一个操作测试多次,以获取操作的平均响应时间。
2. 吞吐量
在给定的时间内,系统支持的事务数量,计算单位为 TPS
通常情况下,借助于自动化工具来进行性能测试
如:ApacheBench、ApacheJMeter、WCAT、WebPolygraph、LoadRunner
二、ApacheBench 工具
ApacheBench(ab)是一款ApacheServer 基准的测试工具,用户测试Apache Server的服务能力(每秒处理请求数),它不仅用于Apache的测试,还可以用于测试Tomcat、Nginx、lighthttp、IIS等服务器。
1. AB 工具安装
httpd-tools软件包由YUM-EPEL源提供
[root@hadoop104 ~]# yum -y install epel-release.noarch
[root@hadoop104 ~]# yum -y install httpd-tools
2. 查看版本号
[root@hadoop104 ~]# ab -V
3. tomcat压力测试
1)编写测试网页:
[root@hadoop104 ~]# vim /usr/local/tomcat/webapps/ROOT/hello.html
<html><head></head><body>hello</body></html>
2)tomcat压测
10个请求10个并发:
[root@hadoop104 ~]# ab -n 10 -c 10 https://192.168.10.104/hello.html
Benchmarking 192.168.10.104 (be patient).....done
Server Software: Apache-Coyote/1.1
# 服务器名称
Server Hostname: 192.168.10.104
# 服务器端口
Server Port: 443
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,1024,256
# 文档路径
Document Path: /hello.html
# 文档大小
Document Length: 52 bytes
# 并发数
Concurrency Level: 10
# 测试消耗的时间
Time taken for tests: 0.139 seconds
# 测试次数
Complete requests: 10
# 失败的请求数
Failed requests: 0
Write errors: 0
# 传输的总数据量
Total transferred: 3590 bytes
# html文档的总数据量
HTML transferred: 520 bytes
# 平均每秒的请求数
Requests per second: 71.76 [#/sec] (mean)
# N个并发请求一次的平均时间
Time per request: 139.354 [ms] (mean)
# 1个并发请求一次的平均时间
Time per request: 13.935 [ms] (mean, across all concurrent requests)
# 传输速率
Transfer rate: 25.16 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 5 62 27.7 71 90
Processing: 1 23 13.2 27 36
Waiting: 1 23 13.3 27 36
Total: 29 86 33.6 105 110
# 各时间范围完成请求数
Percentage of the requests served within a certain time (ms)
50% 105
66% 105
75% 110
80% 110
90% 110
95% 110
98% 110
99% 110
100% 110 (longest request)
3)1000个请求1000个并发
[root@hadoop104 tomcat]# ab -n 1000 -c 1000 http://192.168.10.104/hello.html
