使用ab命令做简单的压力测试.
1、修改虚拟机hosts文件,使其解析域名linuxidc.example.com
- echo -e '192.168.88.131\tlinuxidc.example.com\n192.168.88.131\twww.example.com' >> /etc/hosts
- #追加完成后,直接使用ping linuxidc.example.com和www.example.com测试
2、简单的测试,譬如,200个用户,同时每个发10个请求到网页根目录的index.php文件
- ab -c 200 -n 2000 www.example.com/index.php
-c 有多少个用户同时发送请求, -n 总共发出的请求数
下面贴出笔者一个测试的结果作为范例注释:
- This is ApacheBench, Version 2.3 <$Revision: 1373084 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licensed to The Apache Software Foundation, http://www.apache.org/
- #一些版本相关信息等
- Benchmarking linuxidc.example.com (be patient)
- Completed 200 requests
- Completed 400 requests
- Completed 600 requests
- Completed 800 requests
- Completed 1000 requests
- Completed 1200 requests
- Completed 1400 requests
- Completed 1600 requests
- Completed 1800 requests
- Completed 2000 requests
- Finished 2000 requests
- #进度...
- Server Software: Apache/2.4.3 #软件版本
- Server Hostname: linuxidc.example.com #测试主机
- Server Port: 80 #通过80端口
- Document Path: /wp-login.php #测试页面wordpress登陆页面
- Document Length: 242 bytes #测试页面大小
- Concurrency Level: 200 #测试的并发请求数
- Time taken for tests: 18.055 seconds #测试总耗时
- Complete requests: 2000 #全部请求书
- Failed requests: 276 #失败的请求
- (Connect: 0, Receive: 0, Length: 276, Exceptions: 0)
- Write errors: 0
- Non-2xx responses: 1724
- Total transferred: 1771164 bytes #一共传输的字节
- HTML transferred: 999844 bytes #生成的html的内容传输总量
- Requests per second: 110.77 [#/sec] (mean) #大概每秒能完成几个
- Time per request: 1805.550 [ms] (mean) #每个请求大概耗时
- Time per request: 9.028 [ms] (mean, across all concurrent requests) #相对于所有的并发请求,平均每个用时多久
- Transfer rate: 95.80 [Kbytes/sec] received #传输速率...介个真心不高,估计是用的虚拟网卡缘故
- Connection Times (ms) #连接时间
- min mean[+/-sd] median max
- Connect: 0 7 22.6 0 140 #连接
- Processing: 23 1667 2587.2 704 16935 #处理
- Waiting: 0 1665 2587.3 704 16935 #等待
- Total: 24 1674 2593.1 720 16968
- Percentage of the requests served within a certain time (ms)
- 50% 720
- 66% 1198
- 75% 1562
- 80% 2107
- 90% 5423
- 95% 7555
- 98% 9908
- 99% 12855
- 100% 16968 (longest request)
- #某个时间段的平均处理速率.
Ps:
测试时,尽量使用局域网测试,上面的结果,笔者的本地虚拟网卡,的传输速度太慢了,这估计是由于vmware虚拟网卡自身的问题,这已经严重影响了测试的有效性.
测试时,可以开多个控制台,使用vmstat 1和top,以及网页的status进行观察系统满载时的各种详细参数.
ab测试时,尽量使用多个页面,多次测试,去平均值为最好,若测试的精细,可对XCache开启和关闭的效果分别测试,以及apache的mpm的几个工作模型做详细修改测试,以及apache内各种配置的关闭和开启后的效果测,方式都是一样(笔者很多都正在测试).
