我们开发应用,尤其是大型应用的过程中,肯定会遇到性能问题。那么性能问题如何测试呢?
Apache
有自带一个ab
(Apache Benchmarking)工具进行网站的性能压力测试
命令如下
ab -h
我们可以使用上面的命令查看帮助手册
性能测试,命令
ab [options] [http[s]://]hostname[:port]/path
实例:
ab -n100 -c10 http://www.test.com/
命令解释:-n:请求数 -c:并发数,测试的url后面最后一个/
要跟上,否则会报不合法的url
我们在测试的时候,-n跟-c的值不要设置的太大,太大了会让应用直接挂了
执行命令之后返回的结果:
Server Software: nginx
Server Hostname: www.test.com
Server Port: 80
Document Path: /
Document Length: 16986 bytes
Concurrency Level: 10
Time taken for tests: 18.894 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 1794612 bytes
HTML transferred: 1698600 bytes
Requests per second: 5.29 [#/sec] (mean)
Time per request: 1889.368 [ms] (mean)
Time per request: 188.937 [ms] (mean, across all concurrent requests)
Transfer rate: 92.76 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 37 79 113.5 50 1072
Processing: 584 1755 320.2 1848 2140
Waiting: 546 1670 299.0 1778 2061
Total: 624 1834 317.9 1904 2690
Percentage of the requests served within a certain time (ms)
50% 1904
66% 1966
75% 2010
80% 2054
90% 2159
95% 2180
98% 2208
99% 2690
100% 2690 (longest request)
主要需要关心几个指标:
Requests per second: 每秒接受的请求数
Time per request:一个请求需要耗费多少秒
我们在做性能测试优化的过程中,不断的进行测试,看这两个指标的变化,来验证优化的效果。