主要是介绍一些压力测试和性能测试的工具,本文讲解一下ab和http_load在mac的用法。
测试前,前面先把系统的端口限制数改大,看看Mac下面的默认限制
ulimit -a
open files (-n) 2560
2000多的fd数是很小的,我们把他改大,当然我测试过了,也只能开10000而已,Linux可以开6W多,所以:
ulimit -n 10000
在用 ulimit -a 检查一下
open files (-n) 10000
ab
Apache启动
sudo apachectl start
打开Safari浏览器地址栏输入 “http://localhost”,可以看到内容为“It works!”的页面下载安装httpd最新版本
下载链接:http://httpd.apache.org/download.cgicd httpd-2.4.25/support/
ab -c 100 -n 100
//-c并发数 -n请求数
结果
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.baidu.com (be patient).....done
Server Software: BWS/1.1
Server Hostname: www.baidu.com
Server Port: 80
Document Path: /
Document Length: 101944 bytes
Concurrency Level: 100
Time taken for tests: 2.212 seconds ##共使用了多少时间
Complete requests: 100
Failed requests: 96
(Connect: 0, Receive: 0, Length: 96, Exceptions: 0)
Total transferred: 10310757 bytes
HTML transferred: 10214723 bytes
Requests per second: 45.20 [#/sec] (mean) ##每秒多少请求,这个是非常重要的参数数值,服务器的吞吐量
Time per request: 2212.257 [ms] (mean) ##用户平均请求等待时间
Time per request: 22.123 [ms] (mean, across all concurrent requests) ##服务器平均处理时间
Transfer rate: 4551.50 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 16 125 15.8 125 135
Processing: 347 954 297.0 1013 2075
Waiting: 42 319 188.5 391 929
Total: 472 1079 298.3 1138 2210
Percentage of the requests served within a certain time (ms)
50% 1138 ## 50%的请求在1138ms内返回
66% 1294
75% 1311
80% 1322
90% 1350
95% 1392
98% 1459
99% 2210
100% 2210 (longest request)