1.简介 Apache2自带了一个性能测试工具,叫做ab(Apache Benchmarking),它的主要功能是,测试当前的Apache每秒钟能够处理的请求的数量。
2.安装 这个工具在apache2-utils软件包中,需要先安装: sudo apt-get install apache2-utils
3.语法: ab [option] [http[s]://hostname[:port]/path
注意后面的path,这个是必须有的,如果只给出http://hostname则会出错,后面必须给出路径。
4.示例 向 http://localhost:8899/
发出20000个请求,每次发出200个
ab -n 20000 -c 200 http://localhost:8899/
以下为测试结果:
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
//以下为进度指示
Benchmarking localhost (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests
Server Software: Apache/2.2.22
Server Hostname: localhost
Server Port: 8899
//URL路径
Document Path: /
//文档长度
Document Length: 177 bytes
//并发数
Concurrency Level: 200
//测试所花费的时间
Time taken for tests: 3.289 seconds
//完成的请求数
Complete requests: 20000
//失败的请求数
Failed requests: 0
Write errors: 0
//总共传输的字节数
Total transferred: 9100000 bytes
//总共传输的HTML的字节数
HTML transferred: 3540000 bytes
//平均每秒钟处理的请求数(mean是平均的意思)
Requests per second: 6080.18 [#/sec] (mean)
//平均每个请求所花费的时间。单位是毫秒。这个时间,是每个请求从开始的那个时刻到结束的那个时刻的时间差的平均值
Time per request: 32.894 [ms] (mean)
//每个请求实际运行的平均时间,单位是毫秒。这个时间,是每个请求实际在cpu运行时间的平均值。对于并发请求,CPU并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的;所以,上面的时间约等于时间乘以并发请求数(即ab的-c参数所指定的数值)
Time per request: 0.164 [ms] (mean, across all concurrent requests)
//传输速率,每秒钟收到的千字节(KB)数(如果流量过大,则可能导致响应变慢)
Transfer rate: 2701.64 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 31.6 1 1001
Processing: 7 22 136.8 12 3268
Waiting: 7 22 136.8 12 3268
Total: 10 24 140.8 13 3276
Percentage of the requests served within a certain time (ms)
50% 13
66% 13
75% 20
80% 22
90% 25
95% 26
98% 26
99% 32
100% 3276 (longest request)