常用linux命令:ab压力测试
ab是apache自带的压力测试工具。ab命令会创建多个并发访问线程,模拟多个访问者同时对某一URL地址进行访问
// 安装(如果不安装apache但是又想使用ab命令,可以直接安装apache的工具包httpd-tools)
$ yum -y install httpd-tools
// 查看是否安装成功
$ ab -V
This is ApacheBench, Version 2.3 <$Revision: 1430300 gt;
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
// 常用参数
-n 执行的请求数量
-c 并发请求个数
// 示例
$ ab -n10 -c3 https://www.baidu.com
This is ApacheBench, Version 2.3 <$Revision: 1430300 gt;
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: 443 // 服务器端口
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
Document Path: / // 文件路径
Document Length: 227 bytes // 页面字节数
Concurrency Level: 3 // 并发数
Time taken for tests: 0.271 seconds // 总访问时间
Complete requests: 10 // 请求成功数量
Failed requests: 0 // 请求失败数量
Write errors: 0
Total transferred: 10820 bytes // 请求总数据大小(包括header头信息)
HTML transferred: 2270 bytes // HTML传输字节数
Requests per second: 36.86 [#/sec] (mean) // 每秒处理请求数,mean表示这是一个平均值
Time per request: 81.385 [ms] (mean) // 用户平均请求等待时间
Time per request: 27.128 [ms] (mean, across all concurrent requests) // 服务器平均处理时间
Transfer rate: 38.95 [Kbytes/sec] received // 传输速率
Connection Times (ms)
min mean[+/-sd] median max
Connect: 38 49 5.5 49 57
Processing: 13 16 1.7 16 19
Waiting: 13 16 1.7 16 19
Total: 51 65 7.0 65 76
Percentage of the requests served within a certain time (ms)
50% 65 // 50%用户请求在65ms内返回
66% 66
75% 66
80% 74
90% 76
95% 76
98% 76
99% 76 // %99用户请求在76ms内返回
100% 76 (longest request)