压测比较常用的工具:ab,webbench,jmeter
ab和webbench作为shell模式下轻量级的测试工具,ab比webbench功能更多一些
jmeter作为有GUI界面的更高级测试工具
ab和jmeter同是apache下的两款压测工具
ab是Apache组织开发的一款web压力测试工具,优点是使用方便,统计功能强大
命令格式
ab [options] [http://]hostname[:port]/path
比较常用的有 -n, -t , -c
-c(concurrency)表示用多少并发来进行测试
-t表示测试持续多长时间
-n表示要发送多少次测试请求
eg:
D:\wamp64\bin\apache\apache2.4.39\bin>ab -n 100 -c 100 http://127.0.0.1:8080/test 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 127.0.0.1 (be patient).....done Server Software: Server Hostname: 127.0.0.1 Server Port: 8080 Document Path: /test Document Length: 2 bytes Concurrency Level: 100 Time taken for tests: 0.185 seconds Complete requests: 100 Failed requests: 0 Total transferred: 13400 bytes HTML transferred: 200 bytes Requests per second: 541.03 [#/sec] (mean) Time per request: 184.833 [ms] (mean) Time per request: 1.848 [ms] (mean, across all concurrent requests) Transfer rate: 70.80 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.5 0 1 Processing: 26 126 41.7 146 174 Waiting: 2 80 38.5 72 146 Total: 26 126 41.6 147 175 Percentage of the requests served within a certain time (ms) 50% 147 66% 154 75% 159 80% 161 90% 165 95% 168 98% 171 99% 175 100% 175 (longest request)
jmeter是一个非常强大和用户友好的GUI工具,http访问的参数设置基本应有尽有
结果
对比:
jmeter是一次完整的请求和返回;AB只是发出去请求,并不对返回做处理
jmeter可以提供更加详细的统计结果数据;ab的结果为用数学方式统计平均值
jmeter支持可变参数和CSV数据集的输入,能设定更加负责的测试样例;AB不需要写配置文件
jmeter不支持精确时间的压测;AB支持
jmeter为GUI的较重,并且统计了很多结果数据,比AB耗时耗费资源多;AB属于轻量级