在unix论坛上流传过用F5把一台FreeBSD服务器刷死的帖子, 后来我也试了一下, 除了CPU占用率稍上升其它一切正常. 后来想再试一下压力测试. 搜了一下压力测试方法.原来apache已经带了一个测试工具: ab 一般把apache压力测试称为AB测试. ab工具的位置在apache2的bin目录里.ab的使用是这样的: $Content$nbsp;./ab ./ab: wrong number of arguments Usage: ./ab [options] [http://]hostname[:port]/path Options are: -n requests Number of requests to perform -c concurrency Number of multiple requests to make -t timelimit Seconds to max. wait for responses -p postfile File containing data to POST -T content-type Content-type header for POSTing -v verbosity How much troubleshooting info to print -w Print out results in HTML tables -i Use HEAD instead of GET -x attributes String to insert as table attributes -y attributes String to insert as tr attributes -z attributes String to insert as td or th attributes -C attribute Add cookie, eg. ’Apache=1234. (repeatable) -H attribute Add Arbitrary header line, eg. ’Accept-Encoding: gzip’ Inserted after all normal header lines. (repeatable) -A attribute Add Basic WWW Authentication, the attributes are a colon separated username and password. -P attribute Add Basic Proxy Authentication, the attributes are a colon separated username and password. -X proxy:port Proxyserver and port number to use -V Print version number and exit -k Use HTTP KeepAlive feature -d Do not show percentiles served table. -S Do not show confidence estimators and warnings. -g filename Output collected data to gnuplot format file. -e filename Output CSV file with percentages served -h Display usage information (this message)
参数很多,一般我们用 -c 和 -n 参数就可以了. 例如:
./ab -c 100 -n 10000 http://127.0.0.1/index.php
这个表示同时处理100个请求并运行10000次index.php文件.
过一阵子结果就出来了, 我的机器慢, 过了好一阵子才出来 :)
$Content$nbsp;./ab -c 100 -n 10000 http://127.0.0.1/index.php This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $Content$gt; apache-2.0 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Finished 10000 requests
Server Software: Apache/2.0.53 Server Hostname: 127.0.0.1 Server Port: 80
Document Path: /index.php Document Length: 17998 bytes
Concurrency Level: 100 Time taken for tests: 660.930623 seconds Complete requests: 10000 Failed requests: 0 Write errors: 0 Total transferred: 181850000 bytes HTML transferred: 179980000 bytes Requests per second: 15.13 [#/sec] (mean) Time per request: 6609.306 [ms] (mean) Time per request: 66.093 [ms] (mean, across all concurrent requests) Transfer rate: 268.69 [Kbytes/sec] received
Connection Times (ms) min mean[+/-sd] median max Connect: 0 15 117.6 0 1730 Processing: 436 6564 1142.2 6517 15395 Waiting: 340 4164 1512.2 3906 14973 Total: 436 6579 1143.4 6526 15395
Percentage of the requests served within a certain time (ms) 50% 6526 66% 6972 75% 7262 80% 7377 90% 7755 95% 8295 98% 8683 99% 9815 100% 15395 (longest request) $
|